[cfe-dev] TreeTransform and Clang

Douglas Gregor dgregor at apple.com
Sat Aug 7 04:47:10 PDT 2010


On Aug 7, 2010, at 9:28 AM, Vassil Vassilev wrote:

> Hello,
>  Hm, Is the error handling in the semantic analysis, too?

Yes.

>  I need the following
>  For example (I am skipping the pointers and other ugly things that
> made it less readable):
> 
>  funtion F(int x, float y,string z) {
>     int i = objX.GetValue(x);  //compile time object and method
> invocation
>     TFile t = new TFile("MyFile.hhh");  //here goes the interpreter,but
> it needs addresses of the variables from the compiler
>     i = t.DoSomething(i, x, y, z);
>     Console.WriteLine(i.ToString());
>  }
> 
>  Here the semantic analyzer should say undeclared variable and so on. 

Yes, it will.

>  Before that happens I want to change the AST and to convert it in something like:
> 
>  funtion F(int x, float y,string z) {      
>     int i = objX->GetValue(x);  //compile time object and method invocation      
>     TFile t = new TFile("MyFile.hhh");  //here goes the interpreter,but it needs addresses of the variables from the compiler      
>     Context c = new Context();
>     c.AddVariable(i.GetDeclaration()) ; //here we should use some kind of  reflection or we can insert just the variable address and the proper mapping.   
>     c.AddArgument(x.GetDeclaration());
>     ...
>     Interpreter.Interpret("t->DoSomething(i,x,y,z)", c);
>     i = t.DoSomething(i, x, y, z);
>     Console.WriteLine(i.ToString());   
> } 
> 
>  I know I can modify the Sema and/or put something in the symbol table
> to achieve the goal but I am looking for more elegant solution.

The right way to do this would be to augment Sema's name-lookup facilities, so that your application gets a chance to provide symbols when no other symbols of the same name work. One way to do this is to create your own ExternalASTSource, and override FindExternalVisibleDeclsByName to add those symbols. If I remember correctly, LLDB does this.


> I know
> that probably I can make second pass of the invalid AST but it is not
> the most efficient way of solving the problem. 

You won't be able to make a second pass over the invalid AST; there isn't enough information left to produce a reasonable AST.

	- Doug



More information about the cfe-dev mailing list