diff --git a/src/Generator/Driver.cs b/src/Generator/Driver.cs index 1f5369e2..d1283eb2 100644 --- a/src/Generator/Driver.cs +++ b/src/Generator/Driver.cs @@ -55,8 +55,19 @@ namespace Cxxi var parser = new Parser(Options); parser.HeaderParsed += (file, result) => - Console.WriteLine(result.Success ? " Parsed '" + file + "'." : - " Could not parse '" + file + "'."); + { + switch (result.Kind) + { + case ParserResultKind.Success: + Console.WriteLine(" Parsed '{0}'", file); + break; + case ParserResultKind.Error: + Console.WriteLine(" Error parsing '{0}'", file); + break; + case ParserResultKind.FileNotFound: + Console.WriteLine(" File '{0}' was not found", file); + break; + } parser.ParseHeaders(Options.Headers); Library = parser.Library; diff --git a/src/Parser/Parser.cpp b/src/Parser/Parser.cpp index 2acabebd..6d7dd5d7 100644 --- a/src/Parser/Parser.cpp +++ b/src/Parser/Parser.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -1429,7 +1430,7 @@ ParserResult^ Parser::Parse(const std::string& File) if (File.empty()) { - res->Success = false; + res->Kind = ParserResultKind::FileNotFound; return res; } @@ -1438,6 +1439,15 @@ ParserResult^ Parser::Parse(const std::string& File) 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. @@ -1471,13 +1481,13 @@ ParserResult^ Parser::Parse(const std::string& File) if(DiagClient->getNumErrors() != 0) { - res->Success = false; + res->Kind = ParserResultKind::Error; return res; } AST = &C->getASTContext(); WalkAST(); - res->Success = true; + res->Kind = ParserResultKind::Success; return res; } \ No newline at end of file diff --git a/src/Parser/Parser.h b/src/Parser/Parser.h index 698ad10f..73a90a34 100644 --- a/src/Parser/Parser.h +++ b/src/Parser/Parser.h @@ -61,6 +61,13 @@ public value struct ParserDiagnostic System::String^ Message; }; +public enum struct ParserResultKind +{ + Success, + Error, + FileNotFound +}; + public ref struct ParserResult { ParserResult() @@ -68,7 +75,7 @@ public ref struct ParserResult Diagnostics = gcnew List(); } - bool Success; + ParserResultKind Kind; Cxxi::Library^ Library; List^ Diagnostics; };