[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.tools.cdt] Re: Understanding the DOM AST

Thanks for your answers Andrew,

Andrew Niefer schrieb:
David,
One thing I would point out is that you are resolving the binding for every name you encounter, this can be expensive.

This isnt really importent for me since the parsing is not time critical but good to know.


...

Another way to do things would be to get the ICPPNamespace binding which has a getMemberBindings() method. You might want to look at the NamespaceMemberCollector to see how it does its visit.

Im a bit confused because the same Namespace is (of course) visited multiple times but i get different ICPPASTNamespaceDefinition and ICPPNamespace objects as well as different ICPPClassType objects from the namespaces. Is this intended?



I don't know of any documentation to point you at. For the syntactic AST itself, it would be useful to look at the C++ grammar (I know its in Stroustrup's book, or we used the ISO spec directly).

ok thank you,

David



-Andrew

David Schmelter wrote:
Hello,

as mentioned before im trying to parse some C++ classes and im not sure if my current solution is good/correct.

What i want to achieve is to get all public class declarations (i.e. their names) and template classes (i.e. their names) for a particular namespace (no inner classes) and all public method declarations for these classes.


Right now the only way i have found is to visit all IASTNames and gather the required information from their bindings (as shown below).


public int visit(IASTName name) {
  IBinding binding = name.resolveBinding();
  if (name.isDefinition() && binding instanceof ICPPClassType) {
    ICPPClassType type = (ICPPClassType) binding;
    if(type.getKey() == ICPPClassType.k_class)
      ICPPMethod[] methods = type.getDeclaredMethods();
  }
}


So right now i get the required information from the semantic IBinding hirarchy. However i would expected that i can get the information from the syntactic IASTNode hirarchy as well since i think im just searching some syntactic structure (for instance by visiting IASTDeclarations, but an IASTDeclaration seems not to provide usefull methods for this).


Hence my question is wether my current approach is the right one for my problem or if there is a better solution.

Additionally is there any documentation or paper describing the AST architecture (looking at other posts i think not) or maybe extern papers which describe C++ AST implementations similar to the CDT DOM?

thanks in advance,
David