-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathcodeDog
More file actions
executable file
·173 lines (158 loc) · 6.51 KB
/
codeDog
File metadata and controls
executable file
·173 lines (158 loc) · 6.51 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/usr/bin/env python3
# CodeDog Program Maker
import subprocess
import sys; sys.dont_write_bytecode = True
def _is_required_pyparsing_version(version):
try:
major, minor = version.split(".")[:2]
return (int(major), int(minor)) >= (3, 3)
except (ValueError, TypeError, AttributeError):
return False
try:
import pyparsing
if not _is_required_pyparsing_version(getattr(pyparsing, "__version__", None)):
raise ModuleNotFoundError
except ModuleNotFoundError:
import depsResolve
if subprocess.call(["which", "pip3"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) == 0:
depsResolve.installPyparsing()
else:
depsResolve.installPipPackage()
depsResolve.installPyparsing()
try:
import pyparsing
except Exception:
print("Error attempting to reimport pyparsing")
import progSpec
import codeDogParser
import buildDog
import TestDog
########## Library Shells
import libraryMngr
from codeGenerator import CodeGenerator
#import xlator_JavaScript
from xlator_Swift import Xlator_Swift
from xlator_Java import Xlator_Java
from xlator_CPP import Xlator_CPP
import xlator
import re
import os
import errno
import platform
import copy
import atexit
import threading
from progSpec import cdlog, cdErr
from os.path import abspath
if sys.version_info.major < 3 or (sys.version_info.major == 3 and sys.version_info.minor < 5):
print("\n\nERROR: CodeDog must be used with Python 3.5 or newer\n")
exit(1)
codeDogVersion = '2.0'
runArgs = sys.argv[1:]
if(len(runArgs) < 1):
print("\n usage: codeDog [-v] filename\n")
exit(1)
arg1 = runArgs[0]
if arg1=="-v" or arg1=='--version':
print("\n CodeDog application compiler version "+ codeDogVersion+"\n")
exit(1)
if arg1=="-b" or arg1=='--build':
name = ''
lastArg=1
if(len(runArgs) >1 and runArgs[1][0]!='-'): name = runArgs[1]; lastArg=2
buildDog.buildWithScons(name, runArgs[lastArg:])
exit(1)
if arg1[0]=='-':
print("Unsupported argument:", arg1)
exit(1)
atexit.register(progSpec.whenExit)
codeGenerator = CodeGenerator()
def GenerateProgram(classes, buildTags, tagsList, libsToUse):
result='No Language Generator Found for '+buildTags['Lang']
langGenTag = buildTags['Lang']
if(langGenTag == 'CPP'):
langName='C + +'
xlator = Xlator_CPP()
elif(langGenTag == 'Java'):
langName='J A V A'
xlator = Xlator_Java()
elif(langGenTag == 'Swift'):
langName='S W I F T'
xlator = Xlator_Swift()
else:
cdErr( "ERROR: No language generator found for ".format( langGenTag))
exit(1)
xlator.codeGen = codeGenerator
codeGenerator.xlator = xlator
result=codeGenerator.generate(classes, tagsList, libsToUse, langName)
return result
from timeit import default_timer as timer
def GenerateSystem(classes, buildSpecs, tags, macroDefs):
cdlog(0, "\n###################### G E N E R A T I N G P R O G R A M S P E C I F I C A T I O N")
count=0
for buildSpec in buildSpecs:
count+=1
buildName=buildSpec[0]
buildTags=buildSpec[1]
buildTags['buildName']= buildName
testMode=progSpec.fetchTagValue([tags, buildTags], 'testMode')
progSpec.MarkItems=True
if testMode=='makeTests' or testMode=='runTests':
cdlog(1, "GENERATING: Test Program")
testTagStore=TestDog.generateTestCode(classes, buildTags, tags, macroDefs)
cdlog(1, "Test Program Finished")
tagsList=[tags, buildTags, testTagStore]
else:
tagsList=[tags, buildTags]
#print("BUILDTAGS:", buildTags)
cdlog(0, "\n###################### G E N E R A T I N G S O U R C E C O D E S Y S T E M {} o f {}... ({})".format(count, len(buildSpecs), buildName))
startTime = timer()
libsToUse=libraryMngr.ChooseLibs(classes, buildTags, tags)
chooseLibsTime = timer()-startTime
print("Time Elapsed:", chooseLibsTime)
fileSpecs = GenerateProgram(classes, buildTags, tagsList, libsToUse)
print("Marker: Code Gen Successful")
#GenerateBuildSystem()###################################################
fileName = progSpec.fetchTagValue(tagsList, 'FileName')
labelName = progSpec.fetchTagValue(tagsList, 'Title')
launchIconName = progSpec.fetchTagValue(tagsList, 'LaunchIcon')
programOrLibrary = progSpec.fetchTagValue(tagsList, 'ProgramOrLibrary')
langGenTag = buildTags['Lang']
libFiles=[]
tagsFromLibFiles = libraryMngr.getTagsFromLibFiles()
packageData = []
tools = []
for lib in libsToUse:
if 'interface' in tagsFromLibFiles[lib] and 'libFiles' in tagsFromLibFiles[lib]['interface']:
tmpLibFiles = tagsFromLibFiles[lib]['interface']['libFiles']
libFiles+=tmpLibFiles
if 'packages' in tagsFromLibFiles[lib]['interface']:
packageData = tagsFromLibFiles[lib]['interface']['packages']
if 'tools' in tagsFromLibFiles[lib]['interface']:
tools = tagsFromLibFiles[lib]['interface']['tools']
#TODO: need debug mode and minimum version
platform=progSpec.fetchTagValue([tags, buildTags], 'Platform')
#cdlog(1, "\nWRITING {} FILE(S) AND COMPILING...".format(len(fileSpecs)))
buildDog.build("-g", '14', fileName, labelName, launchIconName, libFiles, buildName, platform, fileSpecs, programOrLibrary, packageData, tools)
print("Marker: Build Successful")
progSpec.rollBack(classes, tags)
# GenerateDocuments()
############################################# L o a d / P a r s e P r o g r a m S p e c
def processMainProgram():
cdlog(0, "\n###################### P R O C E S S I N G M A I N P R O G R A M ######################")
libraryMngr.findLibraryFiles()
filename = abspath(os.getcwd()) + "/" + arg1
[ProgSpec, objNames, macroDefs] = [ {}, [], {} ]
[tagStore, buildSpecs, classes, newClasses] = codeGenerator.loadProgSpecFromDogFile(filename, ProgSpec, objNames, {}, macroDefs)
print("Marker: Parse Successful")
tagStore['dogFilename']=filename
if len(buildSpecs)==0: cdErr('No Build specification was found')
macroDefs= {}
GenerateSystem(classes, buildSpecs, tagStore, macroDefs)
cdlog(0, "\n###################### D O N E")
progSpec.noError=True
threading.stack_size(67108864) # 64MB stack
sys.setrecursionlimit(5000)
thread = threading.Thread(target=processMainProgram)
thread.start()
thread.join()