|
|
@ -2073,56 +2073,12 @@ struct DiagnosticConsumer : public clang::DiagnosticConsumer |
|
|
|
std::vector<Diagnostic> Diagnostics; |
|
|
|
std::vector<Diagnostic> Diagnostics; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
ParserResult^ Parser::ParseHeader(const std::string& File) |
|
|
|
void Parser::HandleDiagnostics(ParserResult^ res) |
|
|
|
{ |
|
|
|
{ |
|
|
|
auto res = gcnew ParserResult(); |
|
|
|
auto DiagClient = (DiagnosticConsumer&) C->getDiagnosticClient(); |
|
|
|
res->Library = Lib; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (File.empty()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
res->Kind = ParserResultKind::FileNotFound; |
|
|
|
|
|
|
|
return res; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SetupHeader(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto SC = new clang::SemaConsumer(); |
|
|
|
|
|
|
|
C->setASTConsumer(SC); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
C->createSema(clang::TU_Complete, 0); |
|
|
|
|
|
|
|
SC->InitializeSema(C->getSema()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto DiagClient = new DiagnosticConsumer(); |
|
|
|
|
|
|
|
C->getDiagnostics().setClient(DiagClient); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check that the file is reachable.
|
|
|
|
|
|
|
|
const clang::DirectoryLookup *Dir; |
|
|
|
|
|
|
|
if (!C->getPreprocessor().getHeaderSearchInfo().LookupFile(File, /*isAngled*/true, |
|
|
|
|
|
|
|
nullptr, Dir, nullptr, nullptr, nullptr, nullptr)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
res->Kind = ParserResultKind::FileNotFound; |
|
|
|
|
|
|
|
return res; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create a virtual file that includes the header. This gets rid of some
|
|
|
|
|
|
|
|
// Clang warnings about parsing an header file as the main file.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string str; |
|
|
|
|
|
|
|
str += "#include \"" + File + "\"" + "\n"; |
|
|
|
|
|
|
|
str += "\0"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto buffer = llvm::MemoryBuffer::getMemBuffer(str); |
|
|
|
|
|
|
|
C->getSourceManager().createMainFileIDForMemBuffer(buffer); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
clang::DiagnosticConsumer* client = C->getDiagnostics().getClient(); |
|
|
|
|
|
|
|
client->BeginSourceFile(C->getLangOpts(), &C->getPreprocessor()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ParseAST(C->getSema(), /*PrintStats=*/false, /*SkipFunctionBodies=*/true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client->EndSourceFile(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Convert the diagnostics to the managed types
|
|
|
|
// Convert the diagnostics to the managed types
|
|
|
|
for each (auto& Diag in DiagClient->Diagnostics) |
|
|
|
for each (auto& Diag in DiagClient.Diagnostics) |
|
|
|
{ |
|
|
|
{ |
|
|
|
using namespace clix; |
|
|
|
using namespace clix; |
|
|
|
|
|
|
|
|
|
|
@ -2168,6 +2124,55 @@ ParserResult^ Parser::ParseHeader(const std::string& File) |
|
|
|
|
|
|
|
|
|
|
|
res->Diagnostics->Add(PDiag); |
|
|
|
res->Diagnostics->Add(PDiag); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ParserResult^ Parser::ParseHeader(const std::string& File) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
auto res = gcnew ParserResult(); |
|
|
|
|
|
|
|
res->Library = Lib; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (File.empty()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
res->Kind = ParserResultKind::FileNotFound; |
|
|
|
|
|
|
|
return res; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SetupHeader(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto SC = new clang::SemaConsumer(); |
|
|
|
|
|
|
|
C->setASTConsumer(SC); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
C->createSema(clang::TU_Complete, 0); |
|
|
|
|
|
|
|
SC->InitializeSema(C->getSema()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto DiagClient = new DiagnosticConsumer(); |
|
|
|
|
|
|
|
C->getDiagnostics().setClient(DiagClient); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check that the file is reachable.
|
|
|
|
|
|
|
|
const clang::DirectoryLookup *Dir; |
|
|
|
|
|
|
|
if (!C->getPreprocessor().getHeaderSearchInfo().LookupFile(File, /*isAngled*/true, |
|
|
|
|
|
|
|
nullptr, Dir, nullptr, nullptr, nullptr, nullptr)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
res->Kind = ParserResultKind::FileNotFound; |
|
|
|
|
|
|
|
return res; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create a virtual file that includes the header. This gets rid of some
|
|
|
|
|
|
|
|
// Clang warnings about parsing an header file as the main file.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string str; |
|
|
|
|
|
|
|
str += "#include \"" + File + "\"" + "\n"; |
|
|
|
|
|
|
|
str += "\0"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto buffer = llvm::MemoryBuffer::getMemBuffer(str); |
|
|
|
|
|
|
|
C->getSourceManager().createMainFileIDForMemBuffer(buffer); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
clang::DiagnosticConsumer* client = C->getDiagnostics().getClient(); |
|
|
|
|
|
|
|
client->BeginSourceFile(C->getLangOpts(), &C->getPreprocessor()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ParseAST(C->getSema(), /*PrintStats=*/false, /*SkipFunctionBodies=*/true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client->EndSourceFile(); |
|
|
|
|
|
|
|
|
|
|
|
if(C->getDiagnosticClient().getNumErrors() != 0) |
|
|
|
if(C->getDiagnosticClient().getNumErrors() != 0) |
|
|
|
{ |
|
|
|
{ |
|
|
|