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 __addVarToRoutine__(self, Routine, CrossReference): globalVar = CrossReference.getGlobalByName(self._varName) if not globalVar: # this is to fix a problem with the name convention of a top level global # like ICD9 can be referred as eith ICD9 or ICD9( altName = getAlternateGlobalName(self._varName) globalVar = CrossReference.getGlobalByName(altName) if globalVar: logger.debug("Changing global name from %s to %s" % (self._varName, altName)) self._varName = altName Routine.addGlobalVariables( GlobalVariable(self._varName, self._varPrefix, self._varValue))
def __addVarToRoutine__(self, Routine, CrossReference): globalVar = CrossReference.getGlobalByName(self._varName) if not globalVar: # this is to fix a problem with the name convention of a top level global # like ICD9 can be referred as eith ICD9 or ICD9( altName = getAlternateGlobalName(self._varName) globalVar = CrossReference.getGlobalByName(altName) if globalVar: logger.debug("Changing global name from %s to %s" % (self._varName, altName)) self._varName = altName Routine.addGlobalVariables(GlobalVariable(self._varName, self._varPrefix, self._varValue))
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 __postParsing__(self, Routine, CrossReference): globalVar = CrossReference.getGlobalByName(self._varName) if not globalVar: globalVar = CrossReference.addNonFileManGlobalByName(self._varName) routineName = Routine.getName() # case to handle the platform dependent routines if CrossReference.isPlatformDependentRoutineByName(routineName): genericRoutine = CrossReference.getGenericPlatformDepRoutineByName(routineName) assert genericRoutine globalVar.addReferencedRoutine(genericRoutine) genericRoutine.addReferredGlobal(globalVar) else: globalVar.addReferencedRoutine(Routine) Routine.addReferredGlobal(globalVar)
def decodeRoutine(self, RoutineJson): crossRef = self._crossRef assert 'name' in RoutineJson assert 'package' in RoutineJson routineName = RoutineJson['name'] packageName = RoutineJson['package'] hasSourceCode = False if "source_code" in RoutineJson: hasSourceCode = RoutineJson['source_code'] if not crossRef.hasRoutine(RoutineJson['name']): crossRef.addRoutineToPackageByName(routineName, packageName, hasSourceCode) Routine = crossRef.getRoutineByName(routineName) assert Routine.getPackage().getName() == packageName self.__setRoutineProperties__(Routine, RoutineJson) for item in ('local_variables', 'global_variables', 'marked_items', 'label_references', 'naked_globals'): self.__handleAbstractVariables__(item, Routine, RoutineJson) self.__handleReferredGlobals__(Routine, RoutineJson) self.__handleCalledRoutines__(Routine, RoutineJson)
def __addVarToRoutine__(self, Routine, CrossReference): Routine.addNakedGlobals( NakedGlobal(self._varName, self._varPrefix, self._varValue))
def __addVarToRoutine__(self, Routine, CrossReference): Routine.addLabelReference(LabelReference(self._varName, self._varPrefix, self._varValue))
def __addVarToRoutine__(self, Routine, CrossReference): Routine.addMarkedItems(MarkedItem(self._varName, self._varPrefix, self._varValue))
def __addVarToRoutine__(self, Routine, CrossReference): Routine.addNakedGlobals(NakedGlobal(self._varName, self._varPrefix, 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 outputRoutine(self, Routine): outputDict = dict() if isinstance(Routine, PlatformDependentGenericRoutine): platformList = self.__outputPlatformDepRoutineList__(Routine) outputDict["platform_dep_list"] = platformList outputDict["name"] = Routine.getName() outputDict["package"] = Routine.getPackage().getName() outputDict["comments"] = Routine.getComment() outputDict["original_name"] = Routine.getOriginalName() outputDict["source_code"] = Routine.hasSourceCode() localVars = self.__outputAbstractVariables__( Routine.getLocalVariables()) outputDict["local_variables"] = localVars globalVars = self.__outputAbstractVariables__( Routine.getGlobalVariables()) outputDict["global_variables"] = globalVars nakedVars = self.__outputAbstractVariables__(Routine.getNakedGlobals()) outputDict["naked_globals"] = nakedVars markedItems = self.__outputAbstractVariables__( Routine.getMarkedItems()) outputDict["marked_items"] = markedItems labelRefs = self.__outputAbstractVariables__( Routine.getLabelReferences()) outputDict["label_references"] = labelRefs outputDict["referred_globals"] = self.__outputReferredGlobals__( Routine.getReferredGlobal()) outputDict["total_called_routines"] = Routine.getTotalCalled() outputDict["called_routines"] = self.__outputCallDepRoutines__( Routine.getCalledRoutines()) outputDict["caller_routines"] = self.__outputCallDepRoutines__( Routine.getCallerRoutines()) return json.dumps(outputDict)
def outputRoutine(self, Routine): outputDict = dict() if isinstance(Routine, PlatformDependentGenericRoutine): platformList = self.__outputPlatformDepRoutineList__(Routine) outputDict["platform_dep_list"] = platformList outputDict["name"] = Routine.getName() outputDict["package"] = Routine.getPackage().getName() outputDict["comments"] = Routine.getComment() outputDict["original_name"] = Routine.getOriginalName() outputDict["source_code"] = Routine.hasSourceCode() localVars = self.__outputAbstractVariables__(Routine.getLocalVariables()) outputDict["local_variables"] = localVars globalVars = self.__outputAbstractVariables__(Routine.getGlobalVariables()) outputDict["global_variables"] = globalVars nakedVars = self.__outputAbstractVariables__(Routine.getNakedGlobals()) outputDict["naked_globals"] = nakedVars markedItems = self.__outputAbstractVariables__(Routine.getMarkedItems()) outputDict["marked_items"] = markedItems labelRefs = self.__outputAbstractVariables__(Routine.getLabelReferences()) outputDict["label_references"] = labelRefs outputDict["referred_globals"] = self.__outputReferredGlobals__(Routine.getReferredGlobal()) outputDict["total_called_routines"] = Routine.getTotalCalled() outputDict["called_routines"] = self.__outputCallDepRoutines__(Routine.getCalledRoutines()) outputDict["caller_routines"] = self.__outputCallDepRoutines__(Routine.getCallerRoutines()) return json.dumps(outputDict)
def __addVarToRoutine__(self, Routine, CrossReference): Routine.addLocalVariables( LocalVariable(self._varName, self._varPrefix, self._varValue))
def __handleReferredGlobals__(self, Routine, RoutineJson): referredGlobalsJson = RoutineJson.get('referred_globals') if not referredGlobalsJson: return for referredGlobal in referredGlobalsJson: Routine.addReferredGlobal( self._crossRef.getGlobalByName(referredGlobal))
def __setRoutineProperties__(self, Routine, RoutineJson): if "original_name" in RoutineJson: Routine.setOriginalName(RoutineJson['original_name']) if "comments" in RoutineJson and RoutineJson['comments']: for comment in RoutineJson['comments']: Routine.addComment(comment)
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 __addVarToRoutine__(self, Routine, CrossReference): Routine.addMarkedItems( MarkedItem(self._varName, self._varPrefix, self._varValue))
def __addVarToRoutine__(self, Routine, CrossReference): Routine.addLabelReference( LabelReference(self._varName, self._varPrefix, self._varValue))
def __handleReferredGlobals__(self, Routine, RoutineJson): referredGlobalsJson = RoutineJson.get('referred_globals') if not referredGlobalsJson: return for referredGlobal in referredGlobalsJson: Routine.addReferredGlobal(self._crossRef.getGlobalByName(referredGlobal))
def __addVarToRoutine__(self, Routine, CrossReference): Routine.addLocalVariables(LocalVariable(self._varName, self._varPrefix, self._varValue))