コード例 #1
0
ファイル: code_templates_ORM.py プロジェクト: LYGTeam/works
    def handle_leaf(self, yinNode):   
        cpp_type, default = None, None
        for subN in yinNode.subNodes:
            if subN.match('type'):
                cpp_type = subN.cpp_type
                if cpp_type == 'tEnumeration':
                    e = dict()
                    for ex_subN in subN.subNodes:
                        if ex_subN.match('enum'):
                            e_id = yinNode.mod_name + '_' + yinNode.identifier + '_' + ex_subN.identifier
                            e_val = None
                            for ex2_subN in ex_subN.subNodes:
                                if ex2_subN.match('value'):
                                    e_val = ex2_subN.value
                            e[e_id] = e_val
                    em = simple_syntax.enumeration(yinNode.mod_name + '_' + yinNode.identifier, e)
                    self.enums.append(em)
            elif subN.match('default'):
                default = subN.default
        if not cpp_type:
            iutil.ERROR('leaf<%s> under node<%s> has no cpp_type!' % (yinNode.identifier, self.tag))
        yinNode.cpp_type, yinNode.default = cpp_type, default
        
        if (yinNode.identifier == self.keyName):
            self.keyNode = yinNode
        if yinNode.parNode != self.yinNode:
            yinNode.identifier = yinNode.mod_name + '_' + yinNode.identifier
        mv = leafVariable(yinNode)
        if yinNode.default:
            #TODO: Handle default statements
            if yin_common.isOrmStringType(yinNode.cpp_type):
                yinNode.default = '\"%s\"' % yinNode.default
            elif yinNode.cpp_type == yin_common.tUnion:
                yinNode.default = None
            elif yinNode.cpp_type == yin_common.tEnumeration:
                yinNode.default = None
            elif yinNode.cpp_type == yin_common.tInstanceIdentifier:
                yinNode.default = None
            elif yinNode.cpp_type == yin_common.tIdentityref:
                yinNode.default = None
            elif yinNode.cpp_type == yin_common.tBits:
                yinNode.default = None
            mv.default = yinNode.default

        # Get & Set
        pre = 'const ' if yin_common.isOrmStringType(yinNode.cpp_type) else iutil.nullStr
        getter = simple_syntax.function(pre + yinNode.cpp_type, iutil.namingConvert('get_'+yinNode.identifier), [])
        getter.inline = True
        getter.impBody.append('return %s.getValue();' % mv.identifier)
        mv.getter = getter
        param = simple_syntax.var_param(pre + yinNode.cpp_type, 'rhs')
        setter = simple_syntax.function('void', iutil.namingConvert('set_'+yinNode.identifier), [param])
        setter.inline = True
        setter.impBody.append('%s.set(%s);' % (mv.identifier, param.identifier))
        mv.setter = setter
        self.subLeafVars.append(mv)
        return mv
コード例 #2
0
ファイル: code_templates_ORM.py プロジェクト: LYGTeam/works
 def handle_case(self, yinNode):
     self.refine_variable_stmt(yinNode)
     mv = leafVariable(yinNode)
     mv.complex = True
     getter = simple_syntax.function(yinNode.cpp_type+'&', iutil.namingConvert('get_'+yinNode.identifier), [])
     getter.inline = True
     getter.impBody.append('return %s;' % mv.identifier)
     self.subLeafVars.append(mv)
コード例 #3
0
ファイル: code_templates_ORM.py プロジェクト: LYGTeam/works
    def __init__(self, mod_prefix, yinNode):
        yinNode.cpp_type = 'ca_' + iutil.namingConvert_Luc(yinNode.identifier)
        ormClass.__init__(self, mod_prefix, yinNode, yinNode.cpp_type)

        self.mf_getElementType.impBody = []
        self.mf_getElementType.impBody.append('return E_Element_Case;')
        
        self.mf_getCaseName = simple_syntax.function(yin_common.tString, 'getCaseName', [])
        self.mf_getCaseName.inline = True
        self.mf_getCaseName.impBody = []
        self.mf_getCaseName.impBody.append('return %s(\"%s\");' % (yin_common.tString, self.yinNode.identifier))
コード例 #4
0
ファイル: code_templates_ORM.py プロジェクト: LYGTeam/works
    def __init__(self, mod_prefix, yinNode):
        yinNode.cpp_type = 'ch_' + iutil.namingConvert_Luc(yinNode.identifier)
        ormClass.__init__(self, mod_prefix, yinNode, yinNode.cpp_type)

        self.cases = {}

        self.mf_getElementType.impBody = []
        self.mf_getElementType.impBody.append('return E_Element_Choice;')

        self.mv_curCase = simple_syntax.variable(yin_common.tString, 'm_curCase')
        self.pri_memb.append(self.mv_curCase)
        
        self.mf_getCurCase = simple_syntax.function(yin_common.tString, 'getCurCase', [])
        self.mf_getCurCase.impBody = []
        self.mf_getCurCase.impBody.append('return %s;' % self.mv_curCase.identifier)
        self.pub_func.append(self.mf_getCurCase)
    
        params = [simple_syntax.var_param(yin_common.tString, 'strCase', False, True, False, False, False)]
        self.mf_setCurCase = simple_syntax.function('bool', 'setCurCase', params)
        self.pub_func.append(self.mf_setCurCase)
コード例 #5
0
ファイル: code_templates_ORM.py プロジェクト: LYGTeam/works
    def __init__(self, mod_prefix, yinNode):
        #yinNode.cpp_type = iutil.namingConvert_Luc(yinNode.getKeyPath())
        #new_cpp_type = iutil.namingConvert_Luc(yinNode.getKeyPath()) + '_lm'
        new_cpp_type = 'lm_' + iutil.namingConvert_Luc(yinNode.identifier)
        yinNode.cpp_type = new_cpp_type
        map_item_type = 'l_' + iutil.namingConvert_Luc(yinNode.identifier)
        ormClass.__init__(self, mod_prefix, yinNode, new_cpp_type)
        
        self.mf_getElementType.impBody = []
        self.mf_getElementType.impBody.append('return E_Element_List;')
        
        # Map part
        self.itemName = map_item_type
        self.itemPair = ('%s_map_pair' % self.itemName)
        self.itemMap = ('%s_map' % self.itemName)
        self.itemIter = ('%s_map_iter' % self.itemName)
        
        mv = simple_syntax.variable(self.itemIter, 'iter')
        mv.complex = True
        self.pri_memb.append(mv)
                
        # Special functions for list
        self.mf_beginInst = simple_syntax.function('bool', 'beginInst', [])
        self.mf_beginInst.inline = True
        self.mf_beginInst.impBody.append("iter = list_m.begin();")
        self.mf_beginInst.impBody.append("return iter != list_m.end();")

        self.mf_isNextInstAvail = simple_syntax.function('bool', 'isNextInstAvail', [])
        self.mf_isNextInstAvail.inline = True
        #self.mf_isNextInstAvail.impBody.append("iter = %s.begin();\n" % self.itemName)
        self.mf_isNextInstAvail.impBody.append("return iter != list_m.end();")
        
        self.mf_getNextInst = simple_syntax.function('bool', 'getNextInst', [])
        self.mf_getNextInst.inline = True
        self.mf_getNextInst.impBody.append("iter ++;")
        self.mf_getNextInst.impBody.append("return true;")
        
        self.mf_flushInstances = simple_syntax.function('bool', 'flushInstances', [])
        self.mf_flushInstances.inline = True
        self.mf_flushInstances.impBody.append("list_m.clear();")
        self.mf_flushInstances.impBody.append("return true;")
コード例 #6
0
ファイル: code_templates_ORM.py プロジェクト: LYGTeam/works
    def __init__(self, mod_prefix, yinNode, cpp_ident):
        #print(yinNode.getKeyPath())
        code_templates.class_template.__init__(self, cpp_ident, 'ConfDDataObject')
        #TODO: The rule to identify namespace and tag is based on ConfD, which is not guarunteed
        self.mod_prefix = mod_prefix
        self.yinNode = yinNode
        self.KeyList = []
        self.keyName = None
        self.keyNode = None
        self.subLeafVars = []
        self.enums = []
        self.typedefs = []
        
        # Common public member functions
        self.mf_getNumAttrs = simple_syntax.function(yin_common.uint32_t, 'getNumAttrs', [])
        self.mf_getNumAttrs.inline = True
        self.mf_getNumAttrs.impBody.append('return numAttrs_c;')

        self.mf_getNumTags = simple_syntax.function(yin_common.uint8_t, 'getNumTags', [])
        self.mf_getNumTags.inline = True
        self.mf_getNumTags.impBody.append('return numTags_c;')

        self.mf_getNumAttrsDmsDataType = simple_syntax.function(yin_common.uint32_t, 'getNumAttrsDmsDataType', [])
        self.mf_getNumAttrsDmsDataType.inline = True
        self.mf_getNumAttrsDmsDataType.impBody.append('return numAttrsDmsDataType_c;')

        self.mf_getNumAttrsForDmsTagDataType = simple_syntax.function(yin_common.uint32_t, 'getNumAttrsForDmsTagDataType', [])
        self.mf_getNumAttrsForDmsTagDataType.inline = True
        self.mf_getNumAttrsForDmsTagDataType.impBody.append('return numAttrsDmsTagDataType_c;')
        
        self.mf_setDefVal = simple_syntax.function('void', 'setDefaultValues', [])
        
        self.mf_copy = simple_syntax.function('DataObject*', 'copy', [])
        self.mf_copy.virtual = True
        self.mf_copy.impBody.append('%s *dataObjCopy = new %s();' % (cpp_ident, cpp_ident))
        self.mf_copy.impBody.append('*dataObjCopy = *this;')
        self.mf_copy.impBody.append('return dataObjCopy;')
        
        self.mf_resetSpecifiedAllAttrs = simple_syntax.function('void', 'resetSpecifiedAllAttrs', [])
        
        params = [simple_syntax.var_param('bool', 'rhs')]
        self.mf_updateAllAttr = simple_syntax.function('void', 'updateAllAttr', params)
        
        # Common public operators
        params = [simple_syntax.var_param('DmsDataType', 'attr', False, False, True, False, False)]
        self.op_leftShift = simple_syntax.function(yin_common.uint32_t, 'operator<<', params)
        
        params = [simple_syntax.var_param('DmsDataType', 'attr', False, True, False, True, False)]
        self.op_rightShift = simple_syntax.function(yin_common.uint32_t, 'operator>>', params)
        
        params = [simple_syntax.var_param('DmsTagDataType', 'attr', False, False, True, False, False)]
        self.op_leftShiftWithTag = simple_syntax.function(yin_common.uint32_t, 'operator<<', params)
        
        params = [simple_syntax.var_param('DmsTagDataType', 'attr', False, True, False, True, False)]
        self.op_rightShiftWithTag = simple_syntax.function(yin_common.uint32_t, 'operator>>', params)
        
        # Common protected functions
        self.mf_getDataType = simple_syntax.function(yin_common.uint8_t, 'getDataType', [])
        self.mf_getDataType.inline = True
        
        self.mf_getElementType = simple_syntax.function(yin_common.uint8_t, 'getElementType', [])
        self.mf_getElementType.inline = True
        #self.mf_getElementType.impBody.append('return %s;' % self.elemType)
    
        self.mf_getKeyReg = simple_syntax.function('bool', 'getKeyReq', [])
        self.mf_getKeyReg.inline = True
        self.mf_getKeyReg.virtual = True
        self.mf_getKeyReg.impBody.append('return true;')
    
        self.mf_getNameSpace = simple_syntax.function(yin_common.uint32_t, 'getNameSpace', [])
        self.mf_getNameSpace.inline = True
        self.mf_getNameSpace.impBody.append('return %s__ns;' % iutil.taggingConvert(self.mod_prefix))
        #self.mf_getNameSpace.impBody.append('return 0;')
        
        self.mf_getTag = simple_syntax.function(yin_common.uint32_t, 'getTag', [])
        self.mf_getTag.inline = True
        self.mf_getTag.impBody.append('return %s_%s;' % (iutil.taggingConvert(self.mod_prefix), iutil.taggingConvert(self.yinNode.identifier)))