def enterRead_config_call(self, ctx: ConfigParser.Read_config_callContext): #print('enterRead_config_call: ') readType = ctx.getChild(2).getText() readPath = ctx.path().getText() readVar = ctx.id_str().getText() #print(' ' + readType + ' ' + readPath + ' ' + readVar) rNode = Cm.CfgReadNode(readPath, readType, None) #print('enterRead_config_call: findVar name=' + readVar + ", ret=" + str(Cm.BaseCfgNode.peekNode().findVar(readVar, True))) rVar = Cm.CfgVariable.resolveLhsExpression( readVar, Cm.CfgNumDataType) # read return variable Cm.CfgAssign(rVar, Cm.ConfigAssignType.EQ, rNode)
def enterPoll_config_call(self, ctx: ConfigParser.Poll_config_callContext): #print('enterPoll_config_call: ') readType = ctx.getChild(0).getText() readPath = ctx.path().getText() pollOp = ctx.compare_op().getText() pollVal = ctx.value(0).getText() #print(' ' + readType + ' ' + readPath + ' ' + pollOp + ' ' + pollVal) rtype = Cm.CfgPathHierType.resolve( readType) # poll is compare of read value, so explicitly set type rNode = Cm.CfgReadNode(readPath, rtype, None) pVal = Cm.CfgVariable.resolveRhsExpression( pollVal, Cm.CfgNumDataType) # read compares to a numeric var or instance whileCompare = Cm.CfgCompare(rNode, pollOp, pVal) Cm.CfgWhileNode(whileCompare)
def pyF1ToCfgData(pyNd): ''' convert a py node to appropriate config model data type - returns None on no match form match is checked in following order: int, path w/ read, path only ''' s = __class__.getSourceString(pyNd) # convert py node to a string data = Cm.CfgNumDataType(s) # try converting to int if data.isValid(): return data hstr = __class__.getHierString(s) if hstr: path = Cm.CfgPathDataType(hstr) # try converting to path if path.isValid(): if path.hasCall(): if path.call == '__get__': path.setField() return Cm.CfgReadNode(path, pyNd) if path.call == '__read__': path.setReg() return Cm.CfgReadNode(path, pyNd) print('invalid call in strToCfgDataType path.val=' + path.val + ', path.call=' + path.call) return None # invalid call found else: return path return None