def generateTestCode(classes, buildTags, tags, macroDefs): [testMacros, testResultUtilities]=setResultCode() codeDogParser.AddToObjectFromText(classes[0], classes[1], testResultUtilities , 'Test utility functions') TestSpecFile= progSpec.fetchTagValue([tags, buildTags], 'TestSpec') TestSpecStr = progSpec.stringFromFile(TestSpecFile) + testMacros #print "#################################\n", TestSpecStr [testTagStore, testBuildSpecs, testClasses, newTestClasses] = codeDogParser.parseCodeDogString(TestSpecStr, classes[0], classes[1], macroDefs, "TestDog Specification") # Replace runcode if it isn't there # Here: generate EXEC_TESTS() and RUN_TEST() TestsToRun = progSpec.fetchTagValue([testTagStore], 'TestsToRun') TestList = TestsToRun.split() TestArrayText="" SwitchCaseText="" count=0 for T in TestList: if count>0: TestArrayText+=", " SwitchCaseText+="else " count+=1 TestArrayText += '"'+T+'"' SwitchCaseText += 'if(testName=="'+T+'"){' + T.replace('/', '_') +'()}\n' testBedUtilities = setUtilityCode(TestArrayText, SwitchCaseText) # print "TEST TEXT:", testBedUtilities codeDogParser.AddToObjectFromText(classes[0], classes[1], testBedUtilities, 'Test code' ) return testTagStore
def generateMainFunctionality(classes, tags): # TODO: Some deInitialize items should automatically run during abort(). # TODO: System initCode should happen first in initialize, last in deinitialize. runCode = progSpec.fetchTagValue(tags, 'runCode') Platform = progSpec.fetchTagValue(tags, 'Platform') if Platform != 'Android': mainFuncCode = """ me void: main( ) <- { initialize(String.join(" ", args)) """ + runCode + """ deinitialize() endFunc() } """ if Platform == 'Android': mainFuncCode = """ me void: runDogCode() <- { """ + runCode + """ } """ progSpec.addObject(classes[0], classes[1], 'GLOBAL', 'struct', 'SEQ') codeDogParser.AddToObjectFromText( classes[0], classes[1], progSpec.wrapFieldListInObjectDef('GLOBAL', mainFuncCode), 'Java start-up code')
def extractLibTags(library): global tagsFromLibFiles libTags = loadTagsFromFile(library) tagsFromLibFiles[library] = libTags ReqTags = progSpec.fetchTagValue([libTags], 'requirements') if ReqTags == None: ReqTags = [] if len(ReqTags) > 0: ReqTags = filterReqTags(ReqTags) interfaceTags = progSpec.fetchTagValue([libTags], 'interface') if interfaceTags == None: interfaceTags = [] return [ReqTags, interfaceTags]
def apply(classes, tags, className, dispMode): if dispMode[:4] == 'TAG_': dispModeTagName = dispMode[4:] dispMode = progSpec.fetchTagValue(tags, dispModeTagName) if (dispMode != 'none' and dispMode != 'text' and dispMode != 'draw' and dispMode != 'Proteus' and dispMode != 'toGUI'): cdErr( 'Invalid parameter for display mode in Code Data Display pattern: ' + str(dispMode)) if dispMode == 'none': return global classesToProcess classesToProcess = [className] global classesEncoded #classesEncoded={} if (dispMode == 'Proteus'): processor = structAsProteusWriter() elif (dispMode == 'text'): processor = structToStringWriter() elif (dispMode == 'draw'): processor = structDrawingWriter() processor.addGlobalCode(classes) for classToEncode in classesToProcess: if classToEncode in classesEncoded: continue cdlog(1, " ENCODING " + dispMode + ": " + classToEncode) classesEncoded[classToEncode] = 1 pattern_GenSymbols.apply( classes, {}, [classToEncode]) # Invoke the GenSymbols pattern processor.processStruct(classes, classToEncode) return
def checkIfLibFileMightSatisyNeedWithRequirements(tags, need, libFile, indent): [ReqTags, interfaceTags, featuresNeeded] = extractLibTags(libFile) Requirements = [] LibCanWork = True if need[0] == 'require': LibCanWork = False if 'provides' in interfaceTags: if need[1] in interfaceTags['provides']: #print(indent, '{}REQUIRE: {} in {}'.format(indent, need[1], interfaceTags['provides'])) LibCanWork = True for ReqTag in ReqTags: #print("REQUIREMENT: {}".format(ReqTag)) if ReqTag[0] == 'feature': print( "\n Nested Features should be implemented. Please implement them. (", ReqTag[1], ")n") exit(2) elif ReqTag[0] == 'require': Requirements.append(ReqTag) elif ReqTag[0] == 'tagOneOf': tagToCheck = ReqTag[1] validValues = progSpec.extractListFromTagList(ReqTag[2]) parentTag = progSpec.fetchTagValue(tags, tagToCheck) # E.g.: "platform" if parentTag == None: LibCanWork = False cdErr("ERROR: The tag '" + tagToCheck + "' was not found in" + libFile + ".\n") if not parentTag in validValues: LibCanWork = False return [LibCanWork, Requirements, featuresNeeded]
def codeStructText(classes, attrList, parentClass, classInherits, classImplements, structName, structCode, tags): classAttrs = '' Platform = progSpec.fetchTagValue(tags, 'Platform') if len(attrList) > 0: for attr in attrList: if attr == 'abstract': classAttrs += 'abstract ' if (parentClass != ""): parentClass = parentClass.replace('::', '_') parentClass = progSpec.unwrapClass(classes, structName) parentClass = ' extends ' + parentClass elif classInherits != None: parentClass = ' extends ' + classInherits[0][0] #print "parentClass::: " , parentClass if classImplements != None: parentClass += ' implements ' count = 0 for item in classImplements[0]: if count > 0: parentClass += ', ' parentClass += item count += 1 #print "parentClass:: " , parentClass if structName == "GLOBAL" and Platform == 'Android': classAttrs = "public " + classAttrs S = "\n" + classAttrs + "class " + structName + '' + parentClass + " {\n" + structCode + '};\n' #if classAttrs!='': print "ATTRIBUTE:", classAttrs +"class "+structName+''+parentClass return ([S, ""])
def checkIfLibFileMightSatisyNeedWithRequirements(tags, need, libFile, indent): [ReqTags, interfaceTags] = extractLibTags(libFile) Requirements = [] LibCanWork = True if need[0] == 'require': LibCanWork = False if 'provides' in interfaceTags: if need[1] in interfaceTags['provides']: #print indent, 'REQUIRE: ', need[1], ' in ' ,interfaceTags['provides'] LibCanWork = True for Req in ReqTags: # print "REQUIREMENT:", Req[0], Req[1] if Req[0] == 'feature': print "\n Nested Features should be implemented. Please implement them. (", Req[ 1], ")n" exit(2) elif Req[0] == 'require': Requirements.append(Req) elif Req[0] == 'tagOneOf': tagToCheck = Req[1] validValues = progSpec.extractListFromTagList(Req[2]) parentTag = progSpec.fetchTagValue(tags, tagToCheck) # E.g.: "platform" if parentTag == None: LibCanWork = False cdErr("ERROR: The tag '" + tagToCheck + "' was not found in" + libFile + ".\n") if not parentTag in validValues: LibCanWork = False else: cdlog(1, " Validated: " + tagToCheck + " = " + parentTag) return [LibCanWork, Requirements]
def extractLibTags(library): libTags = loadTagsFromFile(library) tagsFromLibFiles[library] = libTags ReqTags = progSpec.fetchTagValue([libTags], 'requirements') if ReqTags == None: ReqTags = [] elif len(ReqTags) > 0: ReqTags = filterReqTags(ReqTags) interfaceTags = progSpec.fetchTagValue([libTags], 'interface') if interfaceTags == None: interfaceTags = [] featuresTags = progSpec.fetchTagValue([libTags], 'featuresNeeded') featuresNeeded = [] if featuresTags: for feature in featuresTags: featuresNeeded.append(['feature', feature]) return [ReqTags, interfaceTags, featuresNeeded]
def ChooseLibs(classes, buildTags, tags): clearFeaturesHandled() cdlog(0, "\n############## C H O O S I N G L I B R A R I E S") featuresNeeded = progSpec.fetchTagValue([tags], 'featuresNeeded') initialNeeds = [] for feature in featuresNeeded: featuresNeeded.extend(fetchFeaturesNeededByLibrary(feature)) initialNeeds.append(["feature", feature]) solutionOptions = constructANDListFromNeeds([tags, buildTags], initialNeeds, [], "") reduceSolutionOptions(solutionOptions, '') for libPath in solutionOptions[1]: cdlog(2, "USING LIBRARY:" + libPath) return solutionOptions[1]
def generateMainFunctionality(classes, tags): # TODO: Make initCode, runCode and deInitCode work better and more automated by patterns. # TODO: Some deInitialize items should automatically run during abort(). # TODO: Deinitialize items should happen in reverse order. runCode = progSpec.fetchTagValue(tags, 'runCode') mainFuncCode=""" me void: main() <- { //initialize() """ + runCode + """ //deinitialize() } """ progSpec.addObject(classes[0], classes[1], 'GLOBAL', 'struct', 'SEQ') codeDogParser.AddToObjectFromText(classes[0], classes[1], progSpec.wrapFieldListInObjectDef('GLOBAL', mainFuncCode ), 'Swift start-up code')
def getListWidgetMgrCode(classes, listManagerStructName, rowTypeName, fieldName, classOptionsTags): # New listWidgetMgr code generator # Find the model rowWidgetName = rowTypeName + 'Widget' listWidgetStyle = progSpec.fetchTagValue([classOptionsTags], fieldName + '.style.widgetStyle') if listWidgetStyle == None: listWidgetStyle = 'simpleList' modelRef = progSpec.findSpecOf(classes[0], rowWidgetName, 'struct') if modelRef == None: print("modelRef: ", modelRef, rowTypeName) addNewStructToProcess(rowWidgetName, rowTypeName, 'struct', 'rowWidget') filename = './preDynamicTypes/' + listWidgetStyle + '.dog' classSpec = progSpec.stringFromFile(filename) classSpec = classSpec.replace('<ROW_TYPE>', rowTypeName) classSpec = classSpec.replace('<LIST_CLASS_NAME>', listManagerStructName) #print '==========================================================\n'+classSpec codeDogParser.AddToObjectFromText(classes[0], classes[1], classSpec, rowWidgetName)
def codeVarField_Str(convertedType, innerType, typeSpec, fieldName, fieldValueText, className, tags, indent): # TODO: make test case S = "" fieldOwner = progSpec.getTypeSpecOwner(typeSpec) Platform = progSpec.fetchTagValue(tags, 'Platform') # TODO: make next line so it is not hard coded if (Platform == 'Android' and (convertedType == "CanvasView" or convertedType == "FragmentTransaction" or convertedType == "FragmentManager" or convertedType == "Menu" or convertedType == "static GLOBAL" or convertedType == "Toolbar" or convertedType == "NestedScrollView" or convertedType == "SubMenu" or convertedType == "APP" or convertedType == "AssetManager" or convertedType == "ScrollView" or convertedType == "LinearLayout" or convertedType == "GUI" or convertedType == "HorizontalScrollView" or convertedType == "widget" or convertedType == "GLOBAL")): #print " ConvertedType: ", convertedType, " FieldName: ", fieldName S += indent + "public " + convertedType + ' ' + fieldName + ';\n' else: S += indent + "public " + convertedType + ' ' + fieldName + fieldValueText + ';\n' return [S, '']
def ChooseLibs(classes, buildTags, tags): """Entry point to libraryMngr tags: dict """ featuresHandled.clear() cdlog(0, "\n############## C H O O S I N G L I B R A R I E S") featuresNeeded = progSpec.fetchTagValue([tags], 'featuresNeeded') initialNeeds1 = [] for feature in featuresNeeded: featuresNeeded.extend(fetchFeaturesNeededByLibrary(feature)) if not feature in initialNeeds1: initialNeeds1.append(feature) initialNeeds2 = [] for feature in initialNeeds1: initialNeeds2.append(['feature', feature]) solutionOptions = constructANDListFromNeeds([tags, buildTags], initialNeeds2, [], "") reduceSolutionOptions(solutionOptions, '') for libPath in solutionOptions[1]: cdlog(2, "USING LIBRARY:" + str(libPath)) return solutionOptions[1]
def apply(classes, tags, stylerTagName): if not (isinstance(stylerTagName, str)): cdErr("Styler tag name must be a string") stylerTagValue = progSpec.fetchTagValue(tags, stylerTagName) initCode = processStyler(stylerTagValue) code = r""" struct GLOBAL{ our Styler:: styler } struct Styler{ our cdColor[map string]: userColors me cdColor: frGndColor <- Black me cdColor: bkGndColor <- White me cdColor: highlight1Color <- Black me cdColor: highlight2Color <- Cornflower me cdColor: highlight3Color <- OrangeRed me cdColor: primaryTextColor <- Black me cdColor: data1Color <- Cornflower me cdColor: data2Color <- Turquoise me cdColor: data3Color <- Magenta me cdColor: data4Color <- MediumVioletRed me cdColor: data5Color <- OrangeRed me cdColor: data6Color <- Gold our fontSpec:: fontDefault{"Ariel", 10, 0} our fontSpec:: fontTitle{"Ariel", 16, 0} our fontSpec:: fontSmall{"Ariel", 8, 0} our fontSpec: fontVerySmall our fontSpec: fontLabelWidgetAndroid our fontSpec: fontEntryWidgetAndroid our fontSpec: fontTitleAndroid our fontSpec: fontTextAndroid void: setCustomColor(me string: ID, me cdColor: color) <- { our cdColor:: tmpColor <- color userColors.insert(ID, tmpColor) } me cdColor: color(me string: ID, me cdColor: defaultColor) <- { our cdColor[itr map string]: colorItr <- userColors.find(ID) if(colorItr == userColors.end()){ return(defaultColor) }else{ return(colorItr.val) } } // FONT NAMES me string[map string]: userFontNames me string: titleFont me string: normalFont me string: H1_font me string: H2_font me string: H3_font me string: H4_font me string: H5_font me string: H6_font me string: timesFont me string: sansSerifFont me string: comicFont me string: scriptFont me string: monoFont void: setCustomFont(me string: ID, me string: fontName) <- { userFontNames.insert(ID, fontName) } me string: font(me string: ID) <- {return(userFontNames.get(ID))} // FONT SIZES me int[map string]: userFontSizes me int: fontSizeVerySmall me int: fontSizeSmall me int: fontSizeNormalSize me int: fontSizeLarge me int: fontSizeVeryLarge void: setCustomFontSize(me string: ID, me int: fontSize) <- { userFontSizes.insert(ID, fontSize) } me int: fontSize(me string: ID) <- { return(userFontSizes.get(ID)) } // FONT SIZE MODES me mode[pp, dp, sp]: pixelMode <- pp me int: widgetLabelBoxWidth <- 100 me int: widgetValueBoxWidth <- 100 void: INIT()<-{ <INITCODE> Allocate(fontDefault, "ariel", "14") Allocate(fontTitle, "ariel", "20") Allocate(fontSmall, "ariel", "10") Allocate(fontVerySmall, "ariel", "5") Allocate(fontLabelWidgetAndroid, "ariel", "25") Allocate(fontEntryWidgetAndroid, "ariel", "25") Allocate(fontTitleAndroid, "ariel", "25") Allocate(fontTextAndroid, "ariel", "20") } } """ code = code.replace('<INITCODE>', initCode) #print '==========================================================\n'+code codeDogParser.AddToObjectFromText(classes[0], classes[1], code, 'Pattern: MakeStyler')
def apply(classes, tags, stylerTagName): if not (isinstance(stylerTagName, basestring)): cdErr("Styler tag name must be a string") stylerTagValue = progSpec.fetchTagValue(tags, stylerTagName) initCode = processStyler(stylerTagValue) code = r""" struct GLOBAL{ our Styler:: styler } struct Styler{ our cdColor[map string]: userColors me cdColor: frGndColor <- White me cdColor: bkGndColor <- Black me cdColor: highlight1Color <- White me cdColor: highlight2Color <- Cornflower me cdColor: highlight3Color <- OrangeRed our fontSpec:: fontDefault <- ("Ariel", 10, 0) our fontSpec:: fontTitle <- ("Ariel", 16, 0) our fontSpec:: fontSmall <- ("Ariel", 8, 0) void: setCustomColor(me string: ID, me cdColor: color) <- { our cdColor:: tmpColor <- color userColors.insert(ID, tmpColor) } me cdColor: color(me string: ID) <- { return(userColors.get(ID)) } /- FONT NAMES me string[map string]: userFontNames me string: titleFont me string: normalFont me string: H1_font me string: H2_font me string: H3_font me string: H4_font me string: H5_font me string: H6_font me string: timesFont me string: sansSerifFont me string: comicFont me string: scriptFont me string: monoFont void: setCustomFont(me string: ID, me string: fontName) <- { userFontNames.insert(ID, fontName) } me string: font(me string: ID) <- {return(userFontNames.get(ID))} /- FONT SIZES me int[map string]: userFontSizes me int: fontSizeVerySmall me int: fontSizeSmall me int: fontSizeNormalSize me int: fontSizeLarge me int: fontSizeVeryLarge void: setCustomFontSize(me string: ID, me int: fontSize) <- { userFontSizes.insert(ID, fontSize) } me int: fontSize(me string: ID) <- { return(userFontSizes.get(ID)) } /- FONT SIZE MODES me mode[pp, dp, sp]: pixelMode <- pp void: INIT()<-{ <INITCODE> Allocate(fontDefault, "ariel", "14") Allocate(fontTitle, "ariel", "20") Allocate(fontSmall, "ariel", "10") } } """ code = code.replace('<INITCODE>', initCode) #print '==========================================================\n'+code codeDogParser.AddToObjectFromText(classes[0], classes[1], code, 'Pattern: MakeStyler')
def apply(classes, tags, stylerTagName): if not (isinstance(stylerTagName, str)): cdErr("Styler tag name must be a string") stylerTagValue = progSpec.fetchTagValue(tags, stylerTagName) initCode = processStyler(stylerTagValue) code = r""" struct GLOBAL{ our Styler:: styler } struct Styler{ me Map<me string, our cdColor>: userColors me cdColor: frGndColor <- Black me cdColor: bkGndColor <- White me cdColor: highlight1Color <- Black me cdColor: highlight2Color <- Cornflower me cdColor: highlight3Color <- OrangeRed me cdColor: primaryTextColor <- Black me cdColor: data1Color <- Cornflower me cdColor: data2Color <- Turquoise me cdColor: data3Color <- Magenta me cdColor: data4Color <- MediumVioletRed me cdColor: data5Color <- OrangeRed me cdColor: data6Color <- Gold //TODO: Why don't these constructor inits work? our fontSpec:: defaultFont{"Ariel", 10, 0} our fontSpec:: titleFont{"Ariel", 16, 0} our fontSpec:: smallFont{"Ariel", 8, 0} our fontSpec:: verySmallFont{"Ariel", 5, 0} void: setCustomColor(me string: ID, me cdColor: color) <- { our cdColor:: tmpColor <- color userColors.insert(ID, tmpColor) } me cdColor: color(me string: ID, me cdColor: defaultColor) <- { itr Map<me string, our cdColor>: colorItr <- userColors.find(ID) if(colorItr != userColors.end()){return(colorItr.val)} return(defaultColor) } // FONT NAMES me Map<me string, me string>: userFontNames me string: titleFontname me string: normalFontname me string: H1_fontname me string: H2_fontname me string: H3_fontname me string: H4_fontname me string: H5_fontname me string: H6_fontname me string: timesFontname me string: sansSerifFontname me string: comicFontname me string: scriptFontname me string: monoFontname void: setCustomFont(me string: ID, me string: fontName) <- { userFontNames.insert(ID, fontName) } me string: font(me string: ID) <- {return(userFontNames.at(ID))} // FONT SIZES me Map<me string, me int>: userFontSizes me int: verySmallFontSize me int: smallFontSize me int: normalSizeFontSize me int: largeFontSize me int: veryLargeFontSize void: setCustomFontSize(me string: ID, me int: fontSize) <- { userFontSizes.insert(ID, fontSize) } me int: fontSize(me string: ID) <- { return(userFontSizes.at(ID)) } // FONT SIZE MODES me mode[pp, dp, sp]: pixelMode <- pp me int: widgetLabelBoxWidth <- 100 me int: widgetValueBoxWidth <- 100 // OTHER KEY/VALUES me Map<me string, me string>: userStrings void: setCustomString(me string: key, me string: value) <- { userStrings.insert(key, value) } me Map<me string, me int>: userIntegers void: setCustomInteger(me string: key, me string: value) <- { // userIntegers.insert(key, (value)) } me Map<me string, me int>: userDoubles void: setCustomDouble(me string: key, me string: value) <- { // userIntegers.insert(key, (value)) } void: INIT()<-{ <INITCODE> Allocate(defaultFont, "ariel", "14") Allocate(titleFont, "ariel", "20") Allocate(smallFont, "ariel", "10") Allocate(verySmallFont, "ariel", "5") } } """ code = code.replace('<INITCODE>', initCode) #print '==========================================================\n'+code codeDogParser.AddToObjectFromText(classes[0], classes[1], code, 'Pattern: MakeStyler')