def createUnionIdent(self, dict, node): """ 共用体宣言のの識別子に関するディクショナリの生成 corba: idl_name: 宣言のidl上の識別子 name: C++にマッピングされた識別子 name_fq: C++識別子の完全修飾名 scoped_name: [] リスト形式の完全修飾名 switch_type: switchの型 switch_fq_type: switchの完全修飾型 deref_switch_type: switchの非参照型 local: idl_name: 宣言のidl上の識別子 name: C++にマッピングされた識別子 name_fq: C++識別子の完全修飾名 scoped_name: [] リスト形式の完全修飾名 """ self.createIdent(dict, node) cdict = dict['corba'] ldict = dict['local'] switchType = types.Type(node.switchType()) ast.markDefaultCase(node) hasDefault = ast.defaultCase(node) != None (ctype, ltype, is_primitive) = self.getType(switchType) cdict['switch_fq_type'] = ctype cdict['switch_type'] = ctype.split('::')[-1] ldict['switch_fq_type'] = ltype ldict['switch_type'] = ltype.split('::')[-1] return
def createUnionCases(self, dict, node): cases = [] switchType = types.Type(node.switchType()) ast.markDefaultCase(node) outer_environment = id.lookup(node) environment = outer_environment.enter(node.identifier()) for case in node.cases(): c = self.createUnionCase(case, node, switchType, environment) if c != None: cases.append(c) dict['cases'] = cases return dict
def visitUnion(node): outer_environment = id.lookup(node) environment = outer_environment.enter(node.identifier()) scopedName = id.Name(node.scopedName()) name = scopedName.fullyQualify() switchType = types.Type(node.switchType()) exhaustive = ast.exhaustiveMatch(switchType, ast.allCaseLabelValues(node)) defaultCase = ast.defaultCase(node) ast.markDefaultCase(node) hasDefault = defaultCase != None # deal with types constructed here if node.constrType(): node.switchType().decl().accept(self) for n in node.cases(): if n.constrType(): n.caseType().decl().accept(self) # -------------------------------------------------------------- # union::operator{>>, <<}= (cdrStream& _n) [const] # # marshal/ unmarshal individual cases marshal_discriminator = output.StringStream() unmarshal_discriminator = output.StringStream() skutil.marshall(marshal_discriminator, environment, switchType, None, "_pd__d", "_n") skutil.unmarshall(unmarshal_discriminator, environment, switchType, None, "_pd__d", "_n") marshal_cases = output.StringStream() unmarshal_cases = output.StringStream() for c in node.cases(): caseType = types.Type(c.caseType()) decl = c.declarator() decl_scopedName = id.Name(decl.scopedName()) decl_name = decl_scopedName.simple() if defaultCase == c: isDefault = 1 else: isDefault = 0 for l in c.labels(): value = l.value() discrim_value = switchType.literal(value, environment) if l.default(): unmarshal_cases.out("default:") marshal_cases.out("default:") else: unmarshal_cases.out("case " + discrim_value + ":") marshal_cases.out("case " + discrim_value + ":") marshal_cases.inc_indent() skutil.marshall(marshal_cases, environment, caseType, decl, "_pd_" + decl_name, "_n", is_union=1) marshal_cases.out("break;") marshal_cases.dec_indent() unmarshal_cases.inc_indent() unmarshal_cases.out("_pd__default = %d;" % isDefault) skutil.unmarshall(unmarshal_cases, environment, caseType, decl, "_pd_" + decl_name, "_n", is_union=1) unmarshal_cases.out("break;") unmarshal_cases.dec_indent() if not hasDefault and not exhaustive: unmarshal_cases.out("""\ default: _pd__default = 1; break;""") # write the operators stream.out(template.union_operators, name=name, marshal_discriminator=str(marshal_discriminator), unmarshal_discriminator=str(unmarshal_discriminator), marshal_cases=str(marshal_cases), unmarshal_cases=str(unmarshal_cases)) return
def visitUnion(node): outer_environment = id.lookup(node) environment = outer_environment.enter(node.identifier()) scopedName = id.Name(node.scopedName()) name = scopedName.fullyQualify() switchType = types.Type(node.switchType()) exhaustive = ast.exhaustiveMatch(switchType, ast.allCaseLabelValues(node)) defaultCase = ast.defaultCase(node) ast.markDefaultCase(node) defaultMember = "" if defaultCase: defaultLabel = ast.defaultLabel(defaultCase) default_scopedName = id.Name(defaultCase.declarator().scopedName()) defaultMember = default_scopedName.simple() hasDefault = defaultCase != None # Booleans are a special case (isn't everything?) booleanWrap = switchType.boolean() and exhaustive # deal with types constructed here if node.constrType(): node.switchType().decl().accept(self) for n in node.cases(): if n.constrType(): n.caseType().decl().accept(self) # -------------------------------------------------------------- # union::operator{>>, <<}= (cdrStream& _n) [const] # # marshal/ unmarshal individual cases marshal_discriminator = output.StringStream() unmarshal_discriminator = output.StringStream() skutil.marshall(marshal_discriminator,environment, switchType, None, "_pd__d", "_n") skutil.unmarshall(unmarshal_discriminator,environment, switchType, None, "_pd__d", "_n") marshal_cases = output.StringStream() unmarshal_cases = output.StringStream() for c in node.cases(): caseType = types.Type(c.caseType()) decl = c.declarator() decl_scopedName = id.Name(decl.scopedName()) decl_name = decl_scopedName.simple() # *** HERE: only output code once for each case, no matter how # *** many labels; don't bother with the default check -- do # *** it with the switch. Don't think we need _pd__default # *** member. if defaultCase == c: isDefault = 1 else: isDefault = 0 for l in c.labels(): value = l.value() discrim_value = switchType.literal(value, environment) if l.default(): unmarshal_cases.out("default:") else: unmarshal_cases.out("case " + discrim_value + ":") marshal_cases.out("case " + discrim_value + ":") marshal_cases.inc_indent() skutil.marshall(marshal_cases, environment, caseType, decl, "_pd_" + decl_name, "_n") marshal_cases.out("break;") marshal_cases.dec_indent() unmarshal_cases.inc_indent() unmarshal_cases.out("_pd__default = " + str(isDefault) + ";") skutil.unmarshall(unmarshal_cases, environment, caseType, decl, "_pd_" + decl_name, "_n") unmarshal_cases.out("break;") unmarshal_cases.dec_indent() if not hasDefault and not exhaustive: unmarshal_cases.out("""\ default: _pd__default = 1; break;""") if booleanWrap: marshal_cases.out(template.union_default_bool) else: marshal_cases.out(template.union_default) def marshal(stream = stream, exhaustive = exhaustive, hasDefault = hasDefault, defaultCase = defaultCase, environment = environment, defaultMember = defaultMember, marshal_cases = marshal_cases): if not exhaustive: def default(stream = stream, exhaustive = exhaustive, hasDefault = hasDefault, defaultCase = defaultCase, environment = environment, defaultMember = defaultMember): if hasDefault: caseType = types.Type(defaultCase.caseType()) decl = defaultCase.declarator() decl_scopedName = id.Name(decl.scopedName()) decl_name = decl_scopedName.simple() skutil.marshall(stream, environment, caseType, decl, "_pd_" + decl_name, "_n") stream.out(template.union_operators_nonexhaustive, default = default, cases = str(marshal_cases)) else: stream.out(template.union_operators_exhaustive, cases = str(marshal_cases)) # write the operators stream.out(template.union_operators, name = name, marshal_discriminator = str(marshal_discriminator), unmarshal_discriminator = str(unmarshal_discriminator), marshal_cases = marshal, unmarshal_cases = str(unmarshal_cases)) return
def visitUnion(node): outer_environment = id.lookup(node) environment = outer_environment.enter(node.identifier()) scopedName = id.Name(node.scopedName()) name = scopedName.fullyQualify() switchType = types.Type(node.switchType()) exhaustive = ast.exhaustiveMatch(switchType, ast.allCaseLabelValues(node)) defaultCase = ast.defaultCase(node) ast.markDefaultCase(node) hasDefault = defaultCase != None # deal with types constructed here if node.constrType(): node.switchType().decl().accept(self) for n in node.cases(): if n.constrType(): n.caseType().decl().accept(self) # -------------------------------------------------------------- # union::operator{>>, <<}= (cdrStream& _n) [const] # # marshal/ unmarshal individual cases marshal_discriminator = output.StringStream() unmarshal_discriminator = output.StringStream() skutil.marshall(marshal_discriminator,environment, switchType, None, "_pd__d", "_n") skutil.unmarshall(unmarshal_discriminator,environment, switchType, None, "_pd__d", "_n") marshal_cases = output.StringStream() unmarshal_cases = output.StringStream() for c in node.cases(): caseType = types.Type(c.caseType()) decl = c.declarator() decl_scopedName = id.Name(decl.scopedName()) decl_name = decl_scopedName.simple() if defaultCase == c: isDefault = 1 else: isDefault = 0 for l in c.labels(): value = l.value() discrim_value = switchType.literal(value, environment) if l.default(): unmarshal_cases.out("default:") marshal_cases.out("default:") else: unmarshal_cases.out("case " + discrim_value + ":") marshal_cases.out("case " + discrim_value + ":") marshal_cases.inc_indent() skutil.marshall(marshal_cases, environment, caseType, decl, "_pd_" + decl_name, "_n", is_union=1) marshal_cases.out("break;") marshal_cases.dec_indent() unmarshal_cases.inc_indent() unmarshal_cases.out("_pd__default = %d;" % isDefault) skutil.unmarshall(unmarshal_cases, environment, caseType, decl, "_pd_" + decl_name, "_n", is_union=1) unmarshal_cases.out("break;") unmarshal_cases.dec_indent() if not hasDefault and not exhaustive: unmarshal_cases.out("""\ default: _pd__default = 1; break;""") # write the operators stream.out(template.union_operators, name = name, marshal_discriminator = str(marshal_discriminator), unmarshal_discriminator = str(unmarshal_discriminator), marshal_cases = str(marshal_cases), unmarshal_cases = str(unmarshal_cases)) return