if type.is_ptr:
type = type.base_type
entry = env.lookup(type.name)
- function = entry.type.scope.lookup(self.operators[self.operator])
+ function = entry.type.scope.lookup("operator%s" % self.operator)
if not function:
error(self.pos, "'%s' operator not defined for %s"
% (self.operator, type))
self.type_error()
return
self.type = function.type.return_type
-
- operators = {
- "++": u"__inc__",
- "--": u"__dec__",
- "*": u"__deref__",
- "not": u"__not__" # TODO(danilo): Also handle in NotNode.
- }
"**": "PyNumber_Power"
}
- operators = {
- "+": u"__add__",
- "-": u"__sub__",
- "*": u"__mul__",
- "/": u"__div__",
- "%": u"__mod__",
-
- "<<": u"__lshift__",
- ">>": u"__rshift__",
-
- "&": u"__and__",
- "|": u"__or__",
- "^": u"__xor__",
- }
-
class IntBinopNode(NumBinopNode):
# Binary operation taking integer arguments.
if type2.is_ptr:
type2 = type2.base_type
entry = env.lookup(type1.name)
- function = entry.type.scope.lookup(self.operators[self.operator])
+ function = entry.type.scope.lookup("operator%s" % self.operator)
if not function:
error(self.pos, "'%s' operator not defined for '%s %s %s'"
% (self.operator, type1, self.operator, type2))
if self.cascade:
self.cascade.annotate(code)
- operators = {
- "<": u"__le__",
- ">": u"__gt__",
- "==": u"__eq__",
- "<=": u"__le__",
- ">=": u"__ge__",
- "!=": u"__ne__",
- "<>": u"__ne__"
- }
-
class CascadedCmpNode(Node, CmpNode):
# A CascadedCmpNode is not a complete expression node. It
self.generate_typedef(entry, code)
elif type.is_struct_or_union:
self.generate_struct_union_definition(entry, code)
- elif type.is_cpp_class:
- self.generate_cpp_class_definition(entry, code)
elif type.is_enum:
self.generate_enum_definition(entry, code)
elif type.is_extension_type and entry not in vtabslot_entries:
self.generate_typedef(entry, code)
elif type.is_struct_or_union:
self.generate_struct_union_definition(entry, code)
- elif type.is_cpp_class:
- self.generate_cpp_class_definition(entry, code)
elif type.is_enum:
self.generate_enum_definition(entry, code)
elif type.is_extension_type:
code.putln("#pragma pack(pop)")
code.putln("#endif")
- def generate_cpp_class_definition(self, entry, code):
- code.mark_pos(entry.pos)
- type = entry.type
- scope = type.scope
- if scope:
- kind = type.kind
- packed = type.is_cpp_class and type.packed
- if packed:
- kind = "%s %s" % (type.kind, "__Pyx_PACKED")
- code.globalstate.use_utility_code(packed_struct_utility_code)
- header, footer = \
- self.sue_header_footer(type, kind, type.cname)
- code.putln("")
- if packed:
- code.putln("#if !defined(__GNUC__)")
- code.putln("#pragma pack(push, 1)")
- code.putln("#endif")
- code.putln(header)
- var_entries = scope.var_entries
- for attr in var_entries:
- code.putln(
- "%s;" %
- attr.type.declaration_code(attr.cname))
- code.putln(footer)
- if packed:
- code.putln("#if !defined(__GNUC__)")
- code.putln("#pragma pack(pop)")
- code.putln("#endif")
-
def generate_enum_definition(self, entry, code):
code.mark_pos(entry.pos)
type = entry.type