def choose(switchType = switchtype, values = ast.allCaseLabelValues(node), environment = environment): switchType = switchType.deref() def min_unused(start, used = values): x = start while x in used: x = x + 1 return x kind = switchType.type().kind() if switchType.integer(): (low, high) = ast.integer_type_ranges[kind] s = switchType.literal(min_unused(low+1)) return s elif kind == idltype.tk_char: all = map(chr, range(0, 255)) elif kind == idltype.tk_boolean: all = [0, 1] elif kind == idltype.tk_enum: all = switchType.type().decl().enumerators() else: util.fatalError("Failed to generate a default union " +\ "discriminator value") possibles = util.minus(all, values) return switchType.literal(possibles[0], environment)
def visitInterface(self, node): self.__allInterfaces.append(node) # listed scope and interface name dict = self.createDecl('interface') self.createInterfaceIdent(dict, node) self.createInterfaceFileInfo(dict, node) dict['inherits'] = [] for ihnode in ast.allInherits(node): idict = self.createDecl('inherit') self.createInterfaceIdent(idict, ihnode) self.createInterfaceFileInfo(idict, ihnode) dict['inherits'].append(idict) env = id.lookup(node) allInterfaces = [node]# + ast.allInherits(node) allCallables = util.fold( map(lambda x:x.callables(), allInterfaces), [], lambda x, y: x + y ) dict['operations'] = [] dict['attributes'] = [] for c in allCallables: if isinstance(c, idlast.Attribute): attrType = types.Type(c.attrType()) d_attrType = attrType.deref() (corba_atype, local_atype, is_primitive) = self.getType(attrType) for i in c.identifiers(): ident = id.mapID(i) returnType = attrType.op(types.RET) inType = attrType.op(types.IN) adict = createDecl('attribute') cdict = adict['corba'] ldict = adict['local'] cdict['base_type'] = corba_atype; ldict['base_type'] = local_atype cdict['name'] = ident adict['return'] = self.createReturn(c) adict['arg'] = {} self.createArg(adict['arg'], attrType, False) dict['attributes'].append(adict) if c.readonly(): dict['readonly'] = 'yes' dict['attributes'].append(gdict) elif isinstance(c, idlast.Operation): # operations op_dict = self.createOperation(c) op_dict['return'] = self.createReturn(c) op_dict['args'] = self.createArgs(c, env) dict['operations'].append(op_dict) else: util.fatalError("Internal error generating interface member") raise "No code for interface member: " + repr(c) # self.dict['interfaces'].append(dict) self.dict['tree'].append(dict) return
def run(tree, args): """Entrypoint to the doil backend""" global run_before if run_before: util.fatalError("Sorry, the doil backend cannot process more " "than one IDL file at a time.") run_before = 1 dirname, filename = os.path.split(tree.file()) basename,ext = os.path.splitext(filename) config.state['Basename'] = basename config.state['Directory'] = dirname process_args(args) if config.state['MappingFile'] == '': config.state['TypeMapping'] = {} else: import yaml mapping_file = config.state['MappingFile'] f = open(mapping_file, "r") mapping = yaml.load(f.read()) f.close() config.state['TypeMapping'] = mapping try: # Check the input tree only contains stuff we understand support.checkIDL(tree) # initialise the handy ast module ast.__init__(tree) tree.accept(id.WalkTree()) # Initialise the descriptor generating code # currently doil does not use descriptor # descriptor.__init__(tree) from omniidl_be.doil import dictbuilder dict = dictbuilder.run(tree, config.state) if config.state['Interface']: from omniidl_be.doil import interface interface.generate_interface(dict) interface.generate_types(dict) if config.state['CORBAServant']: from omniidl_be.doil import corba corba.generate_servant(dict) corba.generate_types(dict) if config.state['CORBAAdapter']: from omniidl_be.doil import corba corba.generate_adapter(dict) corba.generate_types(dict) if config.state['CORBAProxy']: from omniidl_be.doil import corba corba.generate_proxy(dict) corba.generate_types(dict) if config.state['IceSlice']: from omniidl_be.doil import ice ice.generate_slice(dict) if config.state['IceAdapter']: from omniidl_be.doil import ice ice.generate_adapter(dict) if config.state['IceProxy']: from omniidl_be.doil import ice ice.generate_proxy(dict) if config.state['IceServant']: from omniidl_be.doil import ice ice.generate_servant(dict) except AttributeError, e: name = e[0] unsupported_visitors = map(lambda x:"visit" + x, AST_unsupported_nodes[:]) if name in unsupported_visitors: util.unsupportedIDL() util.fatalError("An AttributeError exception was caught")
def process_args(args): for arg in args: if arg == "d": config.state['Debug'] = True elif arg[:2] == "m=": config.state['MappingFile'] = arg[2:] elif arg[:2] == "i=": config.state['IncludeHeaders'].append(arg[2:]) # generator options elif arg == "implicit": config.state['ImplicitInclude'] = True elif arg == "interface": config.state['Interface'] = True elif arg == "corbaservant": config.state['CORBAServant'] = True elif arg == "corbaadapter": config.state['CORBAAdapter'] = True elif arg == "corbaproxy": config.state['CORBAProxy'] = True elif arg == "iceslice": config.state['IceSlice'] = True elif arg == "iceservant": config.state['IceServant'] = True elif arg == "iceadapter": config.state['IceAdapter'] = True elif arg == "iceproxy": config.state['IceProxy'] = True # for servant elif arg[:3] == "ss=": config.state['ServantSuffix'] = arg[3:] elif arg[:3] == "sp=": config.state['ServantPrefix'] = arg[3:] elif arg[:4] == "sns=": config.state['ServantNs'] = arg[4:].split('::') elif arg[:5] == "sdir=": config.state['ServantDir'] = arg[5:] # for adapter elif arg[:3] == "as=": config.state['AdapterSuffix'] = arg[3:] elif arg[:3] == "ap=": config.state['AdapterPrefix'] = arg[3:] elif arg[:4] == "ans=": config.state['AdapterNs'] = arg[4:].split('::') elif arg[:5] == "adir=": config.state['AdapterDir'] = arg[5:] # for proxy elif arg[:3] == "ps=": config.state['ProxySuffix'] = arg[3:] elif arg[:3] == "pp=": config.state['ProxyPrefix'] = arg[3:] elif arg[:4] == "pns=": config.state['ProxyNs'] = arg[4:].split('::') elif arg[:5] == "pdir=": config.state['ProxyDir'] = arg[5:] # for interface elif arg[:3] == "is=": config.state['IfaceSuffix'] = arg[3:] elif arg[:3] == "ip=": config.state['IfacePrefix'] = arg[3:] elif arg[:4] == "ins=": config.state['IfaceNs'] = arg[4:].split('::') elif arg[:5] == "idir=": config.state['IfaceDir'] = arg[5:] else: util.fatalError("Argument \"" + str(arg) + "\" is unknown")
corba.generate_proxy(dict) corba.generate_types(dict) if config.state['IceSlice']: from omniidl_be.doil import ice ice.generate_slice(dict) if config.state['IceAdapter']: from omniidl_be.doil import ice ice.generate_adapter(dict) if config.state['IceProxy']: from omniidl_be.doil import ice ice.generate_proxy(dict) if config.state['IceServant']: from omniidl_be.doil import ice ice.generate_servant(dict) except AttributeError, e: name = e[0] unsupported_visitors = map(lambda x:"visit" + x, AST_unsupported_nodes[:]) if name in unsupported_visitors: util.unsupportedIDL() util.fatalError("An AttributeError exception was caught") except SystemExit, e: raise e except: util.fatalError("An internal exception was caught")