This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
[Generic] CALL_EXPR tree code with object ref
- From: charfi asma <charfiasma at yahoo dot fr>
- To: gcc-help at gcc dot gnu dot org
- Date: Thu, 4 Nov 2010 14:42:10 +0000 (GMT)
- Subject: [Generic] CALL_EXPR tree code with object ref
Hello,
I have a class (represented as RECORD_TYPE), and a method of this class
(TYPE_METHODS(class_type) = operation).
operation is a FUNCTION_DECL: tree operation = build_decl(BUILTINS_LOCATION,
FUNCTION_DECL, get_identifier("MyOperation"), operation_type);
I created a variable named "x" of type class_type: tree object =
build_decl(BUILTINS_LOCATION, VAR_DECL, get_identifier("x"), class_type);
I want to use call_expr tree code to call my_method on x (the equivalent of :
x.My_Operation() ).
In this last post http://gcc.gnu.org/ml/gcc-help/2010-10/msg00388.html , Ian
suggest this:
"... To call a method, you have to construct an expression which refers to
the method. In C++, for example, this would mean an expression which
loads a function pointer from a vtable "
but I can not do it :(
1. I tried to follow the cp front end, but I get errors related to GTY.
I tried to include class.c, call.c or method.c to reuse the defined functions
like build_this_parm to add the param "this" to the call_exp, because when I
look at the gimple generated from the c++ call I find that I have to add "this"
to the
function decl and add it also to the call_expr (&c)
main ()
gimple_bind <
struct MyClass x;
gimple_call <MyOperation, NULL, &x>
>
void MyClass::MyOperation() (struct MyClass * const this)
gimple_bind <
GIMPLE_NOP
>
2. I tried also to use the tree code defined in tree.def like COMPONENT_REF (but
it is only used for FIELD_DECL and not TYPE_METHOD of a RECORD_TYPE)
I followed the sfe fe when It calls a function, but it uses a pointer to a
function and not a direct call to the function
I added this :
tree __struct_access_1 = build3(COMPONENT_REF, class_type,operation, x,
NULL_TREE); // exp pour l'objet
tree __call_expr = build_call_expr(__struct_access_1, 0);
append_to_statement_list(__call_expr, &main_stmts);
but I get error when gimplifying the main function
(gdb) n
148 gimplify_function_tree(main_fn_decl);
(gdb) n
Program received signal SIGSEGV, Segmentation fault.
size_binop_loc (loc=0, code=EXACT_DIV_EXPR, arg0=0x0, arg1=0xb743d680)
at ../../gcc-dev/gcc/fold-const.c:1414
1414 tree type = TREE_TYPE (arg0);
3. I tried to use OBJ_TYPE_REF tree code defined in tree.def to get the ref to
an object but I can not find a build_obj_type_ref in the tree.c to use it (just
like build_call_exp ).
If so is familiar with the cp front end or any object oriented fe, I will be
very thankfull if he help me on doing this
thanks a lot
Asma