def add_call_op( self, returns=None, params=[], opt_params=[], this_access=ThisAccess.const, ): try: assert this_access != ThisAccess.static returns = massage_returns(returns) params = massage_params(params) opt_params = massage_params(opt_params) result = None for i in range(0, len(opt_params)+1): call_op = CallOp( self, returns, params + opt_params[0:i], this_access=this_access, ) self.call_ops.append(call_op) if not result: result = call_op return result except Exception as e: self.ext.warning("Ignoring call operator: %s" % (e)) return EmptyCommentContainer()
def add_ctor( self, params=[], opt_params=[], dont_promote=False, dfg_preset_omit=False, ): try: params = massage_params(params) opt_params = massage_params(opt_params) if len(params) == 0 and len(opt_params) == 0: self.include_empty_ctor = False result = None for i in range(0, len(opt_params)+1): ctor = Ctor( self, params + opt_params[0:i], dont_promote=dont_promote, dfg_preset_omit=dfg_preset_omit, ) self.ctors.append(ctor) if not result: result = ctor return result except Exception as e: self.ext.warning("Ignoring ctor: %s" % (e)) return EmptyCommentContainer()
def add_cast( self, dst, this_access=ThisAccess.const, ): try: cast = Cast(self, dst, this_access) self.casts.append(cast) return cast except Exception as e: self.warning("Ignoring cast to %s: %s" % (dst, e)) return EmptyCommentContainer()
def add_bin_op(self, op, returns, params): try: bin_op = BinOp( self, op, massage_returns(returns), massage_params(params), ) self.ext.add_decl(bin_op) return bin_op except Exception as e: self.warning("Ignoring bin_op %s: %s" % (op, e)) return EmptyCommentContainer()
def add_method( self, name, returns=None, params=[], opt_params=[], this_access=ThisAccess.const, kl_name=None, promotion_prolog=None, dfg_preset_omit=False, virtuality=Virtuality.local, ): try: assert isinstance(name, basestring) returns = massage_returns(returns) params = massage_params(params) opt_params = massage_params(opt_params) result = None for i in range(0, len(opt_params)+1): method = Method( self, name, returns, params + opt_params[0:i], this_access=this_access, kl_name=kl_name, promotion_prolog=promotion_prolog, dfg_preset_omit=dfg_preset_omit, virtuality=virtuality, ) self.methods.append(method) if not result: result = method # ensure to disable getters + setters # if they are overriden by special methods for m in self.members: if m.getter_kl_name == name: m.getter_kl_name = None if m.setter_kl_name == name: m.setter_kl_name = None return result except Exception as e: self.ext.warning("Ignoring method '%s': %s" % (name, e)) return EmptyCommentContainer()
def add_func( self, cpp_name, returns=None, params=[], opt_params=[], kl_name=None, promotion_prolog=None, dfg_preset_omit=False, ): cpp_local_name = cpp_name try: cpp_global_name = "::".join(self.nested_cpp_names + [cpp_local_name]) kl_local_name = kl_name if not kl_local_name: kl_local_name = cpp_local_name kl_global_name = "_".join(self.nested_kl_names + [kl_local_name]) returns = massage_returns(returns) params = massage_params(params) opt_params = massage_params(opt_params) result = None for i in range(0, len(opt_params)+1): func = Func( self, cpp_global_name, kl_global_name, returns, params + opt_params[0:i], promotion_prolog=promotion_prolog, dfg_preset_omit=dfg_preset_omit, ) self.ext.add_decl(func) promotion_sig, promotion_cost = func.get_promotion_data() if not promotion_sig in self.ext.func_promotions \ or self.ext.func_promotions[promotion_sig][1] > promotion_cost: self.ext.func_promotions[promotion_sig] = (func, promotion_cost) if not result: result = func return result except Exception as e: self.warning("Ignoring func %s: %s" % (cpp_local_name, e)) return EmptyCommentContainer()
def add_ass_op( self, op, params, ): try: assert isinstance(op, basestring) assert len(params) == 1 params = massage_params(params) ass_op = AssOp( self, op=op, params=params, ) self.ass_ops.append(ass_op) return ass_op except Exception as e: self.warning("Ignoring assignment operator %s: %s" % (op, e)) return EmptyCommentContainer()
def add_uni_op( self, op, returns, kl_method_name=None, ): try: if not kl_method_name: kl_method_name = self.kl_method_name[op] uni_op = UniOp( self, op, kl_method_name, returns, ) self.uni_ops.append(uni_op) return uni_op except Exception as e: self.warning("Ignoring unary operator %s: %s" % (op, e)) return EmptyCommentContainer()
def add_bin_op( self, op, returns, params, ): try: assert isinstance(op, basestring) assert isinstance(returns, basestring) assert len(params) == 2 params = massage_params(params) bin_op = BinOp( self, result_type=returns, op=op, params=params, ) self.bin_ops.append(bin_op) return bin_op except Exception as e: self.warning("Ignoring binary operator %s: %s" % (op, e)) return EmptyCommentContainer()
def add_func( self, cpp_name, returns=None, params=[], opt_params=[], kl_name=None, ): cpp_local_name = cpp_name try: cpp_global_name = "::".join(self.nested_cpp_names + [cpp_local_name]) kl_local_name = kl_name if not kl_local_name: kl_local_name = cpp_local_name kl_global_name = "_".join(self.nested_kl_names + [kl_local_name]) returns = massage_returns(returns) params = massage_params(params) opt_params = massage_params(opt_params) result = None for i in range(0, len(opt_params) + 1): func = Func( self, cpp_global_name, kl_global_name, returns, params + opt_params[0:i], ) self.ext.add_decl(func) if not result: result = func return result except Exception as e: self.warning("Ignoring func %s: %s" % (cpp_local_name, e)) return EmptyCommentContainer()
def add_alias(self, new_cpp_type_name, old_cpp_type_name): try: direct_new_cpp_global_expr = self.cpp_type_expr_parser.parse( new_cpp_type_name).prefix(self.components) direct_old_cpp_global_expr = self.resolve_cpp_type_expr( old_cpp_type_name) self.type_mgr.add_alias(direct_new_cpp_global_expr, direct_old_cpp_global_expr) direct_new_kl_local_name = new_cpp_type_name direct_new_kl_global_name = '_'.join(self.nested_kl_names + [direct_new_kl_local_name]) direct_old_dqti = self.type_mgr.get_dqti( direct_old_cpp_global_expr) print "direct_old_dqti.type_info.kl.name = " + str( direct_old_dqti.type_info.kl.name) print "direct_old_dqti.type_info.edk.name = " + str( direct_old_dqti.type_info.edk.name) print "direct_old_dqti.type_info.lib.name = " + str( direct_old_dqti.type_info.lib.name) print "direct_old_dqti.type_info.lib.expr = " + str( direct_old_dqti.type_info.lib.expr) direct_alias = Alias(self, direct_new_kl_global_name, direct_old_dqti.type_info) self.ext.add_decl(direct_alias) const_ptr_new_cpp_type_expr = PointerTo( Const(direct_new_cpp_global_expr)) const_ptr_old_cpp_type_expr = PointerTo( Const(direct_old_cpp_global_expr)) self.type_mgr.add_alias(const_ptr_new_cpp_type_expr, const_ptr_old_cpp_type_expr) const_ptr_new_kl_type_name = direct_new_kl_global_name + "_CxxConstPtr" const_ptr_old_dqti = self.type_mgr.get_dqti( const_ptr_old_cpp_type_expr) const_ptr_old_kl_type_name = const_ptr_old_dqti.type_info.kl.name.compound const_ptr_alias = Alias(self, const_ptr_new_kl_type_name, const_ptr_old_dqti.type_info) self.ext.add_decl(const_ptr_alias) self.ext.add_kl_epilog(""" %s Make_%s(%s value) { return Make_%s(value); } %s Make_%s(io %s value) { return Make_%s(value); } """ % ( const_ptr_new_kl_type_name, const_ptr_new_kl_type_name, direct_new_kl_global_name, const_ptr_old_kl_type_name, const_ptr_new_kl_type_name, const_ptr_new_kl_type_name, direct_new_kl_global_name, const_ptr_old_kl_type_name, )) mutable_ptr_new_cpp_type_expr = PointerTo( direct_new_cpp_global_expr) mutable_ptr_old_cpp_type_expr = PointerTo( direct_old_cpp_global_expr) self.type_mgr.add_alias(mutable_ptr_new_cpp_type_expr, mutable_ptr_old_cpp_type_expr) mutable_ptr_new_kl_type_name = direct_new_kl_global_name + "_CxxPtr" mutable_ptr_old_dqti = self.type_mgr.get_dqti( mutable_ptr_old_cpp_type_expr) mutable_ptr_old_kl_type_name = mutable_ptr_old_dqti.type_info.kl.name.compound mutable_ptr_alias = Alias(self, mutable_ptr_new_kl_type_name, mutable_ptr_old_dqti.type_info) self.ext.add_decl(mutable_ptr_alias) self.ext.add_kl_epilog(""" %s Make_%s(%s value) { return Make_%s(value); } %s Make_%s(io %s value) { return Make_%s(value); } """ % ( mutable_ptr_new_kl_type_name, mutable_ptr_new_kl_type_name, direct_new_kl_global_name, mutable_ptr_old_kl_type_name, mutable_ptr_new_kl_type_name, mutable_ptr_new_kl_type_name, direct_new_kl_global_name, mutable_ptr_old_kl_type_name, )) const_ref_new_cpp_type_expr = ReferenceTo( Const(direct_new_cpp_global_expr)) const_ref_old_cpp_type_expr = ReferenceTo( Const(direct_old_cpp_global_expr)) self.type_mgr.add_alias(const_ref_new_cpp_type_expr, const_ref_old_cpp_type_expr) const_ref_new_kl_type_name = direct_new_kl_global_name + "_CxxConstRef" const_ref_old_dqti = self.type_mgr.get_dqti( const_ref_old_cpp_type_expr) const_ref_old_kl_type_name = const_ref_old_dqti.type_info.kl.name.compound const_ref_alias = Alias(self, const_ref_new_kl_type_name, const_ref_old_dqti.type_info) self.ext.add_decl(const_ref_alias) self.ext.add_kl_epilog(""" %s Make_%s(%s value) { return Make_%s(value); } %s Make_%s(io %s value) { return Make_%s(value); } """ % ( const_ref_new_kl_type_name, const_ref_new_kl_type_name, direct_new_kl_global_name, const_ref_old_kl_type_name, const_ref_new_kl_type_name, const_ref_new_kl_type_name, direct_new_kl_global_name, const_ref_old_kl_type_name, )) mutable_ref_new_cpp_type_expr = ReferenceTo( direct_new_cpp_global_expr) mutable_ref_old_cpp_type_expr = ReferenceTo( direct_old_cpp_global_expr) self.type_mgr.add_alias(mutable_ref_new_cpp_type_expr, mutable_ref_old_cpp_type_expr) mutable_ref_new_kl_type_name = direct_new_kl_global_name + "_CxxRef" mutable_ref_old_dqti = self.type_mgr.get_dqti( mutable_ref_old_cpp_type_expr) mutable_ref_old_kl_type_name = mutable_ref_old_dqti.type_info.kl.name.compound mutable_ref_alias = Alias(self, mutable_ref_new_kl_type_name, mutable_ref_old_dqti.type_info) self.ext.add_decl(mutable_ref_alias) self.ext.add_kl_epilog(""" %s Make_%s(%s value) { return Make_%s(value); } %s Make_%s(io %s value) { return Make_%s(value); } """ % ( mutable_ref_new_kl_type_name, mutable_ref_new_kl_type_name, direct_new_kl_global_name, mutable_ref_old_kl_type_name, mutable_ref_new_kl_type_name, mutable_ref_new_kl_type_name, direct_new_kl_global_name, mutable_ref_old_kl_type_name, )) return direct_alias except Exception as e: self.ext.warning("Ignoring alias '%s': %s" % (new_cpp_type_name, e)) return EmptyCommentContainer()