How to add a class to the tree

Klesk kleskmail@gmail.com
Sat Aug 1 15:08:00 GMT 2009


Hi

I would like something else... I think I wasn't specific enough..
let's try again :)
I have:

SampleClass object;

While parsing gcc will try to find what 'SampleClass' is, but  because
it was not defined by user it will signal an error. Generally I would
like to avoid getting an error without modifying source given above,
so I would like to create programmically a simple class when it's
impossible to find  it.

By 'create programmically' I mean: write a function which will create
a tree_node (I think it's needed)  representing a class named
'SampleClass' and then add it to the tree representing source code.
Function would called when there's no definition for 'SampleClass'.

2009/8/1 Amittai Aviram <amittai.aviram@yale.edu>:
> On Aug 1, 2009, at 5:11 AM, Klesk wrote:
>
>> Let's say I have code like this:
>>
>> SampleClass object;
>>
>> which of course fails to compile because there is no SampleClass.
>>
>> How to programmically create a class named SampleClass to make it
>> possible to complie ?
>>
>>
>> -- Klesk
>
>
> Hi, Kiesk!
>
> #include <iostream>
>
> class SampleClass {
>  private:
>   int id;
>  public:
>  SampleClass() {
>   id = 42;
>  }
>  int get_id() {
>   return id;
>  }
> };
>
> int main(int argc, char ** argv) {
>
>  SampleClass object;
>  std::cout << object.get_id() << std::endl;
>  return EXIT_SUCCESS;
> }
>
>
> Do you mean something else?  By "programmatically create," do you mean
> create dynamically at runtime, as you would using the reflection mechanisms
> of Java or C#?
>
> Thanks.
>
>
> Amittai Aviram
> Graduate Student in Computer Science
> Yale University
> 646 483 2639
> amittai.aviram@yale.edu
> http://www.amittai.com
>
>



-- 
Klesk



More information about the Gcc-help mailing list