def unitTestRoutineJSONEncoder(outputFile): testPA = Package("TestPA") testPB = Package("TestPB") testPC = Package("TestPC") calledRoutineA = Routine("TestRA", testPB) calledRoutineB = Routine("TestRB", testPC) testRoutine = Routine("TestRA", testPA) localVar = LocalVariable("TSTLA",">>","YU+4,XU+1*") testRoutine.addLocalVariables(localVar) localVar = LocalVariable("TSTLB",">>","YU+1*,XU+3*") testRoutine.addLocalVariables(localVar) globalVar = GlobalVariable("TSTGA",">>","YU+4,XU+1*") testRoutine.addGlobalVariables(globalVar) nakedVar = NakedGlobal("^(20.2",None,"YU+4,XU+1") testRoutine.addNakedGlobals(nakedVar) labelRef = LabelReference("DD",None,"YU+4,XU+1") testRoutine.addLabelReference(labelRef) globalVar = Global("^TMP(\"TEST\"", None, None, None) testRoutine.addReferredGlobal(globalVar) globalVar = Global("^TMP($J", None, None, None) testRoutine.addReferredGlobal(globalVar) testRoutine.addCalledRoutines(calledRoutineA,"$$DT","N+1,Y+3") testRoutine.addCalledRoutines(calledRoutineB,"$$OUT","Y+1,Z+3") output = RoutineJSONEncoder().outputRoutine(testRoutine) outputFile = open(outputFile, "wb") outputFile.write(output) outputFile.write("\n")
def __postParsing__(self, Routine, CrossReference): routineDetail = routineTag.search(self._varName.strip()) if routineDetail: routineName = routineDetail.group('name') if not validRoutineName.search(routineName): logger.warning("invalid Routine Name: %s in routine:%s, package: %s" % (routineName, Routine, Routine.getPackage())) return if (routineName.startswith("%")): CrossReference.addPercentRoutine(routineName) # ignore mumps routine for now if CrossReference.isMumpsRoutine(routineName): return # routineName=routineName[1:] if CrossReference.routineNeedRename(routineName): routineName = CrossReference.getRenamedRoutineName(routineName) tag = "" if routineDetail.group('external'): tag += routineDetail.group('external') if routineDetail.group('tag'): tag += routineDetail.group('tag') if not CrossReference.hasRoutine(routineName): # automatically categorize the routine by the namespace # if could not find one, assign to Uncategorized defaultPackageName = "Uncategorized" (namespace, package) = CrossReference.categorizeRoutineByNamespace(routineName) if namespace and package: defaultPackageName = package.getName() CrossReference.addRoutineToPackageByName(routineName, defaultPackageName, False) routine = CrossReference.getRoutineByName(routineName) Routine.addCalledRoutines(routine, tag, self._varValue)
def __postParsing__(self, Routine, CrossReference): routineDetail = routineTag.search(self._varName.strip()) if routineDetail: routineName = routineDetail.group('name') if not validRoutineName.search(routineName): logger.warning( "invalid Routine Name: %s in routine:%s, package: %s" % (routineName, Routine, Routine.getPackage())) return if (routineName.startswith("%")): CrossReference.addPercentRoutine(routineName) # ignore mumps routine for now if CrossReference.isMumpsRoutine(routineName): return # routineName=routineName[1:] if CrossReference.routineNeedRename(routineName): routineName = CrossReference.getRenamedRoutineName(routineName) tag = "" if routineDetail.group('external'): tag += routineDetail.group('external') if routineDetail.group('tag'): tag += routineDetail.group('tag') if not CrossReference.hasRoutine(routineName): # automatically categorize the routine by the namespace # if could not find one, assign to Uncategorized defaultPackageName = "Uncategorized" (namespace, package ) = CrossReference.categorizeRoutineByNamespace(routineName) if namespace and package: defaultPackageName = package.getName() CrossReference.addRoutineToPackageByName( routineName, defaultPackageName, False) routine = CrossReference.getRoutineByName(routineName) Routine.addCalledRoutines(routine, tag, self._varValue)
def unitTestRoutineJSONEncoder(outputFile): testPA = Package("TestPA") testPB = Package("TestPB") testPC = Package("TestPC") calledRoutineA = Routine("TestRA", testPB) calledRoutineB = Routine("TestRB", testPC) testRoutine = Routine("TestRA", testPA) localVar = LocalVariable("TSTLA", ">>", "YU+4,XU+1*") testRoutine.addLocalVariables(localVar) localVar = LocalVariable("TSTLB", ">>", "YU+1*,XU+3*") testRoutine.addLocalVariables(localVar) globalVar = GlobalVariable("TSTGA", ">>", "YU+4,XU+1*") testRoutine.addGlobalVariables(globalVar) nakedVar = NakedGlobal("^(20.2", None, "YU+4,XU+1") testRoutine.addNakedGlobals(nakedVar) labelRef = LabelReference("DD", None, "YU+4,XU+1") testRoutine.addLabelReference(labelRef) globalVar = Global("^TMP(\"TEST\"", None, None, None) testRoutine.addReferredGlobal(globalVar) globalVar = Global("^TMP($J", None, None, None) testRoutine.addReferredGlobal(globalVar) testRoutine.addCalledRoutines(calledRoutineA, "$$DT", "N+1,Y+3") testRoutine.addCalledRoutines(calledRoutineB, "$$OUT", "Y+1,Z+3") output = RoutineJSONEncoder().outputRoutine(testRoutine) outputFile = open(outputFile, "wb") outputFile.write(output) outputFile.write("\n")
def __handleCalledRoutines__(self, Routine, RoutineJson): calledRoutines = RoutineJson.get("called_routines") if not calledRoutines: return for calledRoutineJson in calledRoutines: packageRoutines = calledRoutineJson['routines'] for routine in packageRoutines: routineName = routine['routine'] calledRoutine = self._crossRef.getRoutineByName(routineName) assert calledRoutine tags = routine['tags'] for tagDict in tags: Routine.addCalledRoutines(calledRoutine, tagDict['tag'], ",".join(tagDict['occurences']))
def __handleCalledRoutines__(self, Routine, RoutineJson): calledRoutines = RoutineJson.get("called_routines") if not calledRoutines: return for calledRoutineJson in calledRoutines: packageRoutines = calledRoutineJson['routines'] for routine in packageRoutines: routineName = routine['routine'] calledRoutine = self._crossRef.getRoutineByName(routineName) assert calledRoutine tags = routine['tags'] for tagDict in tags: Routine.addCalledRoutines(calledRoutine, tagDict['tag'], ",".join(tagDict['occurences']))