[cfe-dev] Avoid clang::SourceManger's cache

Vassil Vassilev vvasilev at cern.ch
Tue Apr 24 01:25:15 PDT 2012


Hi,
    I am working on the following example:
[cling]$ #include<iostream>
[cling]$ #include<fstream>
[cling]$ std::ofstream myfile;
[cling]$ myfile.open("TmpClassDef.h");
[cling]$ myfile<<  "class MyClass{};\n"
[cling]$ myfile<<  "error_here;";
[cling]$ myfile.close();
[cling]$ #include "TmpClassDef.h"<--- issues error and recovers and
continues:

[cling]$ myfile.open("TmpClassDef.h");
[cling]$ myfile<<  "class MyClass{ \n";
[cling]$ myfile<<  "public: \n";
[cling]$ myfile<<  "  int gimme12(){\n";
[cling]$ myfile<<  "    return 12;\n"
[cling]$ myfile<<  "  }\n"
[cling]$ myfile<<  "};\n";
[cling]$ myfile.close();
[cling]$ #include "TmpClassDef.h"<--- no errors

    However at the last line I hit the SourceManager's cache and it picks
up the old
file (containing the errors).
    My general question is : Is there a way remove the file from the cache?

    I am trying to override the TmpClassDef.h file by using:
SourceManager::overrideFileContents.
The issue is that actually I am overriding the same file with itself. So
if I try to get the
llvm::MemoryBuffer for the same FileID I'd get again the cached one.
    Any ideas are very welcome!
Thanks!
Vassil




More information about the cfe-dev mailing list