Esempio n. 1
0
    def visitConst(self, node):
        node.constType().accept(self)
        type = self.__result_type

        if node.constKind() == idltype.tk_enum:
            value = "::" + idlutil.ccolonName(node.value().scopedName())

        elif node.constKind() == idltype.tk_string:
            value = '"' + idlutil.escapifyString(node.value()) + '"'

        elif node.constKind() == idltype.tk_wstring:
            value = 'L"' + idlutil.escapifyWString(node.value()) + '"'

        elif node.constKind() == idltype.tk_wchar:
            value = "L'" + idlutil.escapifyWString([node.value()]) + "'"

        elif node.constKind() in [
                idltype.tk_float, idltype.tk_double, idltype.tk_longdouble
        ]:
            value = idlutil.reprFloat(node.value())

        elif node.constKind() == idltype.tk_fixed:
            value = node.value() + "d"
        else:
            value = str(node.value())

        self.st.out("""\
const @type@ @id@ = @value@;""",
                    type=type,
                    id=node.identifier(),
                    value=value)
Esempio n. 2
0
    def visitConst(self, node):
        node.constType().accept(self)
        type = self.__result_type

        if node.constKind() == idltype.tk_enum:
            value = "::" + idlutil.ccolonName(node.value().scopedName())

        elif node.constKind() == idltype.tk_string:
            value = '"' + idlutil.escapifyString(node.value()) + '"'

        elif node.constKind() == idltype.tk_wstring:
            value = 'L"' + idlutil.escapifyWString(node.value()) + '"'

        elif node.constKind() == idltype.tk_wchar:
            value = "L'" + idlutil.escapifyWString([node.value()]) + "'"

        elif node.constKind() in [idltype.tk_float, idltype.tk_double,
                                  idltype.tk_longdouble]:
            value = idlutil.reprFloat(node.value())

        elif node.constKind() == idltype.tk_fixed:
            value = node.value() + "d"
        else:
            value = str(node.value())
        
        self.st.out("""\
const @type@ @id@ = @value@;""",
                    type=type, id=node.identifier(), value=value)
Esempio n. 3
0
	def visitConst(self, node):
		if not self.firstRound:
			node.constType().accept(self)
			type = self.__result_type

			if node.constKind() == idltype.tk_string:
				value = '"' + idlutil.escapifyString(node.value()) + '"'
			elif node.constKind() in [idltype.tk_float, idltype.tk_double, idltype.tk_longdouble]:
				value = idlutil.reprFloat(node.value())

			else:
				value = str(node.value())

			self.const.append('const ' + type + ' ' + node.identifier() + ' = ' + value + ';\n')
Esempio n. 4
0
    def literal(self, value, environment = None):
        """literal(types.Type, value any, id.Environment option): string
           Returns a C++ representation of a value"""

        type = self.deref()
        kind = type.__type.kind()

        # (unsigned) short ints are themselves
        if kind in [ idltype.tk_short, idltype.tk_ushort ]:
            return str(value)

        # careful with long ints to avoid "L" postfix
        if kind in [ idltype.tk_long, idltype.tk_ulong ]:
            s = str(value)
            if s[-1] == 'L':             s = s[0:-1]
            if kind == idltype.tk_ulong: s = s + "U"
            return s

        if kind in [ idltype.tk_longlong, idltype.tk_ulonglong ]:
            s = str(value)
            if s[-1] == 'L':                 s = s[:-1]
            if kind == idltype.tk_ulonglong: s = s + "U"
            return "_CORBA_LONGLONG_CONST(" + s + ")"

        if kind in [ idltype.tk_float ]:
            return idlutil.reprFloat(value) + "F"

        if kind in [ idltype.tk_double ]:
            return idlutil.reprFloat(value)

        if kind in [ idltype.tk_longdouble ]:
            return idlutil.reprFloat(value) + "L"

        # chars are single-quoted
        if kind in [ idltype.tk_char ]:
            return "'" + idlutil.escapifyString(value) + "'"

        if kind in [ idltype.tk_wchar ]:
            return "L'" + idlutil.escapifyWString([value], "x") + "'"
        
        # booleans are straightforward
        if kind in [ idltype.tk_boolean ]:
            return str(value)

        if kind in [ idltype.tk_enum ]:
            # value is an enumerator
            enum_name = id.Name(value.scopedName())
            #enum_name = id.Name(type.__type.decl().scopedName() + [str(value)])
            return enum_name.unambiguous(environment)

        if kind in [ idltype.tk_string ]:
            return '"' + idlutil.escapifyString(value) + '"'

        if kind in [ idltype.tk_wstring ]:
            return 'L"' + idlutil.escapifyWString(value, "x") + '"'

        if kind in [ idltype.tk_octet ]:
            return str(value)

        if kind in [ idltype.tk_fixed ]:
            return '"' + value + '"'

        util.fatalError("Internal error when handling value (" +\
                        repr(value) +")" )
Esempio n. 5
0
    def literal(self, value, environment=None):
        """literal(types.Type, value any, id.Environment option): string
           Returns a C++ representation of a value"""

        type = self.deref()
        kind = type.__type.kind()

        # (unsigned) short ints are themselves
        if kind in [idltype.tk_short, idltype.tk_ushort]:
            return str(value)

        # careful with long ints to avoid "L" postfix
        if kind in [idltype.tk_long, idltype.tk_ulong]:
            s = str(value)
            if s[-1] == 'L': s = s[0:-1]
            if kind == idltype.tk_ulong: s = s + "U"
            return s

        if kind in [idltype.tk_longlong, idltype.tk_ulonglong]:
            s = str(value)
            if s[-1] == 'L': s = s[:-1]
            if kind == idltype.tk_ulonglong: s = s + "U"
            return "_CORBA_LONGLONG_CONST(" + s + ")"

        if kind in [idltype.tk_float]:
            return idlutil.reprFloat(value) + "F"

        if kind in [idltype.tk_double]:
            return idlutil.reprFloat(value)

        if kind in [idltype.tk_longdouble]:
            return idlutil.reprFloat(value) + "L"

        # chars are single-quoted
        if kind in [idltype.tk_char]:
            return "'" + idlutil.escapifyString(value) + "'"

        if kind in [idltype.tk_wchar]:
            return "L'" + idlutil.escapifyWString([value], "x") + "'"

        # booleans are straightforward
        if kind in [idltype.tk_boolean]:
            return str(value)

        if kind in [idltype.tk_enum]:
            # value is an enumerator
            enum_name = id.Name(value.scopedName())
            #enum_name = id.Name(type.__type.decl().scopedName() + [str(value)])
            return enum_name.unambiguous(environment)

        if kind in [idltype.tk_string]:
            return '"' + idlutil.escapifyString(value) + '"'

        if kind in [idltype.tk_wstring]:
            return 'L"' + idlutil.escapifyWString(value, "x") + '"'

        if kind in [idltype.tk_octet]:
            return str(value)

        if kind in [idltype.tk_fixed]:
            return '"' + value + '"'

        util.fatalError("Internal error when handling value (" +\
                        repr(value) +")" )