[cfe-dev] Getting the same begin and end locations from TypeLoc?
    Lukhnos Liu 
    lukhnos at lukhnos.org
       
    Tue May 15 20:05:23 PDT 2012
    
    
  
Hi,
In what circumstances would one get the same location by calling the getBeginLoc() and getEndLoc() of a TypeLoc instance?
My setup is like this: I have a SemaConsumer, and from the HandleTranslationUnit method, I descend (via the passed ASTContext's getTranslationUnitDecl()) to the Decl I'm interested in:
  // I is an iterator from a DeclContext's decls_begin()
  if (const DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(*I)) {
    TypeSourceInfo *TSI = DD->getTypeSourceInfo();
    TypeLoc TL = TSI->getTypeLoc();
    SourceLocation B = TL.getBeginLoc();
    SourceLocation E = TL.getEndLoc();
    // want to do something with B and E, e.g. get the characterData from the source manager
  }
And by calling their print(), it turns out that SourceLocations B and E always point to the same place of the source code -- same line, same column, though I expected E to be further down in the source. Did I miss anything in using TypeLoc?
Thanks,
Lukhnos
    
    
More information about the cfe-dev
mailing list