[cfe-dev] context of file given start and end StartLocation

Jan Bierbaum s3306700 at inf.tu-dresden.de
Mon Aug 16 02:14:21 PDT 2010


manavender reddy meinte am 16.08.2010 04:25:
> I was wondering is it possible to get text from file given start and end
> locations (SourceLocation).

std::pair<clang::FileID, unsigned>
  startLocPair = SM.getDecomposedLoc(startLocation),
  endLocPair = SM.getDecomposedLoc(endLocation);

if (startLocPair.first != endLocPair.first)
  //do something

bool invalid;
const char *buffer = SM.getBufferData(startLocPair.first,
  &invalid).data();

if (invalid)
  //do something

const char *codeStart = buffer + startLocPair.second,
           *codeEnd = buffer + endLocPair.second;



I did not test this and probably there's a better solution anyway, but
it should work ;-)


Regards, Jan.



More information about the cfe-dev mailing list