-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathgetLibInfo.py
106 lines (93 loc) · 3.54 KB
/
getLibInfo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env python3
# AnalyzeLib.py
import sys; sys.dont_write_bytecode = True
import re
import codeDogParser
import libraryMngr
import progSpec
from progSpec import cdlog, cdErr, logLvl, dePythonStr
from progSpec import structsNeedingModification
from pyparsing import ParseResults
from pprint import pprint
import os
from os.path import abspath
import errno
classDefs = {}
classNames = []
fileClasses = [classDefs, classNames]
libPaths = []
libsFields = []
if sys.version_info[0] < 3:
print("\n\nERROR: CodeDog must be used with Python 3\n")
exit(1)
codeDogVersion = '2.0'
if(len(sys.argv) < 2):
print("\n usage: codeDog [-v] filename\n")
exit(1)
arg1 = sys.argv[1]
if arg1=="-v" or arg1=='--version':
print("\n CodeDog application compiler version "+ codeDogVersion+"\n")
exit(1)
if arg1[0]=='-':
print("Unsupported argument:", arg1)
exit(1)
##################################################
def makeDir(dirToGen):
try:
os.makedirs(dirToGen)
except OSError as exception:
if exception.errno != errno.EEXIST: raise
def writeFile(libPath):
global libsFields
dirName = "testLibResults"
makeDir(dirName)
libsDir, libName = os.path.split(abspath(libPath))
base=os.path.basename(libPath)
fileName = dirName+"/"+libName+".info"
cdlog(1, "WRITING FILE: "+fileName)
with open(fileName, 'wt') as out: pprint(libsFields, stream=out)
def addToLibFieldsList(filename, fileClasses, newClasses):
global libsFields
libraryClasses = []
for className in newClasses:
fieldsList = []
classDef = fileClasses[0][className]
if 'fields' in classDef:
for fieldDef in classDef['fields']:
if progSpec.fieldIsFunction(fieldDef['typeSpec']):
#print("VALUE: ", fieldDef['value'])
if fieldDef['hasFuncBody'] and (fieldDef['value'][0] or fieldDef['value'][1]):
status = 'Impl'
elif not fieldDef['hasFuncBody']:
status = 'Abstract'
elif fieldDef['hasFuncBody'] and (fieldDef['value'][0] == [] or fieldDef['value'] == ''):
status = 'Empty'
elif 'verbatimText' in fieldDef['typeSpec']:
status = 'Impl'
elif 'codeConverter' in fieldDef['typeSpec']:
status = 'Impl'
else:
print("Unknown: ", fieldDef['value'])
status = 'Unknown'
fieldIDandStatus = {'fieldID':fieldDef['fieldID'], 'status':status}
else: fieldIDandStatus = {'fieldID':fieldDef['fieldID']}
fieldsList.append(fieldIDandStatus)
libraryClass = {'className':className, 'fields': fieldsList}
libraryClasses.append(libraryClass)
library = [filename, libraryClasses]
libsFields.append(library)
def loadLibrary(filename):
global classDefs
global classNames
global fileClasses
codeDogStr = progSpec.stringFromFile(filename)
codeDogStr = libraryMngr.processIncludedFiles(codeDogStr, filename)
[tagStore, buildSpecs, fileClasses, newClasses] = codeDogParser.parseCodeDogString(codeDogStr, fileClasses[0], fileClasses[1], {}, filename)
return [fileClasses, newClasses]
def analyzeLibByName(filename):
[fileClasses, newClasses] = loadLibrary(filename)
addToLibFieldsList(arg1, fileClasses, newClasses)
writeFile(filename)
#filename = "LIBS/"+arg1+".Lib.dog"
filename = arg1
analyzeLibByName(filename)