Re : Re : Re : Classes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Phill,

I declare the operation as a build_decl like this:

    tree myOperation1_decl = build_decl(BUILTINS_LOCATION, FUNCTION_DECL, 
get_identifier("MyOperation1"), myOperation1_type);
    tree myOperation1_tree = create_operation1(myClass_type, myOperation1_decl);
    DECL_CONTEXT(myOperation1_tree) = myClass_type;

In create_operation1 function, I build the body of the operation that modify the 
value of one attribute. thus filed2 is my attribute 

here is the gimple that I produce.
the param is for the "this" to acceed the attribute (this.attribute)

main ()
gimple_bind <
  <unnamed-signed:32> D.34;
  struct MyClass x;

  gimple_call <MyOperation1, NULL, &x>
  gimple_call <MyOperation2, NULL, &x>
  gimple_assign <integer_cst, D.34, 0, NULL>
  gimple_return <D.34>
>


MyOperation2 (struct MyClass * this)
gimple_bind <
  gimple_assign <integer_cst, this->MyAttribute2, 15, NULL>
  gimple_return <NULL>
>


MyOperation1 (struct MyClass * this)
gimple_bind <
  gimple_assign <integer_cst, this->MyAttribute1, 10, NULL>
  gimple_return <NULL>
>

Do not hesitate if you have other questions,

Asma



----- Message d'origine ----
De : Philip Herron <redbrain@xxxxxxxxxxx>
À : charfi asma <charfiasma@xxxxxxxx>
Cc : gcc-help@xxxxxxxxxxx
Envoyé le : Mer 20 avril 2011, 5h 35min 14s
Objet : Re: Re : Re : Classes

Hey again i havent had much time to play with it but my main mis
understanding was in your post:

tree operation_type = build_method_type_directly (class_t, void_type_node,
NULL_TREE);

tree operation = build_decl(BUILTINS_LOCATION, FUNCTION_DECL,
get_identifier("MyOperation"), operation_type);
tree parm = build_decl (BUILTINS_LOCATION, PARM_DECL, get_identifier("this"),
build_pointer_type(class_t));

tree ptr_obj = build1(ADDR_EXPR, build_pointer_type(TREE_TYPE(object)),object);
tree __call_expr = build_call_expr(__field2, 1, ptr_obj);

What is your __field2 ? is this your function in your record_type for
your class? And if so what way do you declare it do you do build_decl
(function_decl) or is it Method_type ?

I really should play around with this now.

--Phil

On 16 April 2011 21:56, charfi asma <charfiasma@xxxxxxxx> wrote:
> Hello Phil,
>
> you will find answer to your question here :
> http://gcc.gnu.org/ml/gcc-help/2010-11/msg00090.html
> Ian suggest that I see the c++ front end and do the same, but it was a little
> diffucult for me ;)
>
> that's why I do it manually : I added the instance param in the CALL_EXPR tree
> code.
> you find also in the post my gimple and the cp gimple they are almost the 
same.
>
> Hope it helps.
>
> Asma
>
>
>
> ----- Message d'origine ----
> De : Philip Herron <redbrain@xxxxxxxxxxx>
> À : charfi asma <charfiasma@xxxxxxxx>
> Cc : gcc-help@xxxxxxxxxxx
> Envoyé le : Ven 15 avril 2011, 8h 39min 35s
> Objet : Re: Re : Classes
>
> On 5 April 2011 08:44, charfi asma <charfiasma@xxxxxxxx> wrote:
>>
>>
>> Hello Phil,
>>
>> have a look at those post:
>>
>> http://gcc.gnu.org/ml/gcc-help/2010-11/msg00019.html
>> http://gcc.gnu.org/ml/gcc-help/2010-10/msg00388.html
>>
>> I got the same problem when I want to add a method to my class.
>>
>> hope it helps
>>
> Hey
>
> Thanks for those links i am a little confused still not sure if i've
> done everything right.
>
> Say for example i wanted to implment this:
>
> int main() ()
> {
>  int D.1710;
>
>  {
>    struct myClass test;
>
>    myClass::set_values (&test, 3, 4);
>    D.1710 = 0;
>    return D.1710;
>  }
>  D.1710 = 0;
>  return D.1710;
> }
>
>
> void myClass::set_values(int, int) (struct myClass * const this, int a, int b)
> {
>  this->x = a;
>  this->y = b;
> }
>
> Which is the gimple dump of:
>
> class myClass
> {
>  int x, y;
>
>  public:
>    void set_values (int, int);
> };
>
> void myClass::set_values (int a, int b)
> {
>  x = a;
>  y = b;
> }
>
> int main ()
> {
>  myClass test;
>
>  test.set_values (3,4);
>
>  return 0;
> }
>
>
> I make a RECORD_TYPE called myClass and having FIELD_DECLS for x and y.
>
> set_values = FUNCTION_DECL....
> Then i use TYPE_METHODS(myClass) = set_values
>
> Then i dont understand how i call the method not sure how i use the
> build_call_expr to do that.
>
>




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux