⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 defs.py

📁 编译工具
💻 PY
📖 第 1 页 / 共 5 页
字号:
        if not outer_has_default and not implicitDefault:            cases.out("default: goto fail;")        # handle situation where have an implicit default member        # (ie no actual case, but a legal set of discriminator values)        # (assumes that the current discriminator is set to one of the        # defaults)        if implicitDefault:            need_switch = 1            cases.out("default:")            cases.out("switch (_value){")            cases.inc_indent()            # again, make sure we aren't currently in the default state            # and trying to set the discriminator to a non-default state            fail_all_but([])            cases.out("default: _pd__d = _value; return;")            cases.dec_indent()            cases.out("}")                              # output the code here        switch = output.StringStream()        if need_switch:            switch.out("switch (_pd__d){\n  @cases@\n};", cases = cases)        stream.out(template.union_d_fn_body, switch = switch)                # get and set functions for each case:    def members(stream = stream, node = node, environment = environment,                choose = chooseArbitraryDefault, switchType = switchType):        for c in node.cases():            # Following the typedef chain will deliver the base type of            # the alias. Whether or not it is an array is stored in an            # ast.Typedef node.            caseType = types.Type(c.caseType())            d_caseType = caseType.deref()            # the mangled name of the member            decl = c.declarator()            decl_dims = decl.sizes()            full_dims = decl_dims + caseType.dims()                        is_array = full_dims != []            is_array_declarator = decl_dims != []            alias_array = caseType.dims() != []            member = id.mapID(decl.identifier())                        memtype = caseType.member(environment)                        # CORBA 2.3 C++ language mapping (June, 1999) 1-34:            # ... Setting the union value through a modifier function            # automatically sets the discriminant and may release the            # storage associated with the previous value ... If a            # modifier for a union member with multiple legal            # discriminant values is used to set the value of the            # discriminant, the union implementation is free to set            # the discriminant to any one of the legal values for that            # member. The actual discriminant value chose under these            # circumstances is implementation-dependent. ...                        # Do we pick the first element (seems obvious)?            # Or pick another one, hoping to trip-up people who write            # non-compliant code and make an incorrect assumption?                        labels = c.labels()            if labels != []:                non_default_labels = filter(lambda x:not x.default(), labels)                if non_default_labels == []:                    # only one label and it's the default                    label = labels[0]                    discrimvalue = choose()                elif len(non_default_labels) > 1:                    # oooh, we have a choice. Let's pick the second one.                    # no-one will be expecting that                    label = non_default_labels[1]                else:                    # just the one interesting label                    label = non_default_labels[0]                if label.default():                    discrimvalue = choose()                else:                    discrimvalue = switchType.literal(label.value(),                                                      environment)                # only different when array declarator                const_type_str = memtype                                # anonymous arrays are handled slightly differently                if is_array_declarator:                    prefix = config.state['Private Prefix']                    stream.out(template.union_array_declarator,                               prefix = prefix,                               memtype = memtype,                               name = member,                               dims = cxx.dimsToString(decl.sizes()),                               tail_dims = cxx.dimsToString(decl.sizes()[1:]))                    const_type_str = prefix + "_" + member                    memtype = "_" + member                             if is_array:                    # build the loop                    def loop(stream = stream, full_dims = full_dims,                             member = member):                        loop = cxx.For(stream, full_dims)                        index = loop.index()                        stream.out("\n_pd_" + member + index + " = _value" +\                                   index + ";\n")                        loop.end()                        return                                        stream.out(template.union_array,                               memtype = memtype,                               const_type = const_type_str,                               name = member,                               isDefault = str(c.isDefault),                               discrimvalue = discrimvalue,                               loop = loop)                                    elif d_caseType.any():                    # note type != CORBA::Any when its an alias...                    stream.out(template.union_any,                               type = memtype,                               name = member,                               isDefault = str(c.isDefault),                               discrimvalue = discrimvalue)                elif d_caseType.typecode():                    stream.out(template.union_typecode,                               name = member,                               isDefault = str(c.isDefault),                               discrimvalue = discrimvalue)                                                    elif isinstance(d_caseType.type(), idltype.Base) or \                     d_caseType.enum():                    # basic type                    stream.out(template.union_basic,                               type = memtype,                               name = member,                               isDefault = str(c.isDefault),                               discrimvalue = discrimvalue)                                    elif d_caseType.string():                    stream.out(template.union_string,                               name = member,                               isDefault = str(c.isDefault),                               discrimvalue = discrimvalue)                elif d_caseType.wstring():                    stream.out(template.union_wstring,                               name = member,                               isDefault = str(c.isDefault),                               discrimvalue = discrimvalue)                elif d_caseType.objref():                    scopedName = d_caseType.type().decl().scopedName()                    name = id.Name(scopedName)                    ptr_name = name.suffix("_ptr").unambiguous(environment)                    Helper_name = name.suffix("_Helper").unambiguous(                        environment)                    var_name = name.suffix("_var").unambiguous(environment)                    stream.out(template.union_objref,                               member = member,                               memtype = memtype,                               ptr_name = ptr_name,                               var_name = var_name,                               Helper_name = Helper_name,                               isDefault = str(c.isDefault),                               discrimvalue = discrimvalue)                elif caseType.typedef() or d_caseType.struct() or \                     d_caseType.union():                    stream.out(template.union_constructed,                               type = memtype,                               name = member,                               isDefault = str(c.isDefault),                               discrimvalue = discrimvalue)                elif d_caseType.sequence():                    sequence_template = d_caseType.sequenceTemplate(environment)                    stream.out(template.union_sequence,                               sequence_template = sequence_template,                               member = member,                               isDefault = str(c.isDefault),                               discrimvalue = discrimvalue)                else:                    util.fatalError("Unknown union case type encountered")        return    # Typecode and Any    def tcParser_unionHelper(stream = stream, node = node):        if config.state['Typecode']:            guard_name = id.Name(node.scopedName()).guard()            stream.out(template.union_tcParser_friend,                       name = guard_name,                       private_prefix = config.state['Private Prefix'])    # declare the instance of the discriminator and    # the actual data members (shock, horror)    # FIXME: there is some interesting behaviour in    # o2be_union::produce_hdr which I should examine more    # carefully    inside = output.StringStream()    outside = output.StringStream()    used_inside = 0    used_outside = 0    for c in node.cases():        # find the dereferenced type of the member if its an alias        caseType = types.Type(c.caseType())        d_caseType = caseType.deref()        decl = c.declarator()        decl_dims = decl.sizes()        full_dims = caseType.dims() + decl_dims                is_array = full_dims != []        is_array_declarator = decl_dims != []        member_name = id.mapID(c.declarator().identifier())        type_str = caseType.member(environment)        # non-array sequences have had their template typedef'd somewhere        if not is_array_declarator and caseType.sequence():            type_str = "_" + member_name + "_seq"                dims_str = cxx.dimsToString(decl_dims)        # Decide what does inside and outside the union {} itself        # Note: floats in unions are special cases        if (d_caseType.float() or d_caseType.double()) and \           not is_array:            inside.out(template.union_noproxy_float,                       type = type_str, name = member_name,                       dims = dims_str)            outside.out(template.union_proxy_float,                       type = type_str, name = member_name,                       dims = dims_str)            used_inside = used_outside = 1        else:            if is_array and d_caseType.struct() and \               not caseType.variable():                this_stream = inside                used_inside = 1            else:                if d_caseType.type().kind() in \                   [ idltype.tk_struct, idltype.tk_union,                     idltype.tk_except, idltype.tk_string,                     idltype.tk_wstring,                     idltype.tk_sequence, idltype.tk_any,                     idltype.tk_TypeCode, idltype.tk_objref ]:                                                                     this_stream = outside                    used_outside = 1                else:                    this_stream = inside                    used_inside = 1            this_stream.out(template.union_member,                            type = type_str,                            name = member_name,                            dims = dims_str)    discrimtype = d_switchType.base(environment)        if used_inside:        _union = output.StringStream()        _union.out(template.union_union, members = str(inside))        inside = _union    # write out the union class    stream.out(template.union,               unionname = cxx_id,               fixed = fixed,               Other_IDL = Other_IDL,               default_constructor = default_constructor,               copy_constructor = copy_constructor,               discrimtype = discrimtype,               _d_body = _d_fn,               implicit_default = implicit_default,               members = members,               tcParser_unionHelper = tcParser_unionHelper,               union = str(inside),               outsideUnion = str(outside))    if types.variableDecl(node):        stream.out(template.union_variable_out_type,                   unionname = cxx_id)    else:        stream.out(template.union_fix_out_type,                   unionname = cxx_id)    self.__insideClass = insideClass    # TypeCode and Any    if config.state['Typecode']:        qualifier = const_qualifier(self.__insideModule, self.__insideClass)        stream.out(template.typecode,                   qualifier = qualifier,                   name = cxx_id)    returndef visitUnionForward(node):    cxx_name = id.mapID(node.identifier())    stream.out(template.union_forward, name = cxx_name)def visitEnum(node):    name = id.mapID(node.identifier())    enumerators = node.enumerators()    memberlist = map(lambda x: id.Name(x.scopedName()).simple(), enumerators)    stream.out(template.enum,               name = name,               memberlist = string.join(memberlist, ", "))    # TypeCode and Any    if config.state['Typecode']:        qualifier = const_qualifier(self.__insideModule, self.__insideClass)        stream.out(template.typecode,                   qualifier = qualifier, name = name)        return

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -