Browse Source

Changed the generator to get the AST of each header individually. This fixes some problems that the old way had related to keeping track of forward references.

pull/1/head
triton 13 years ago
parent
commit
3c0b6e5620
  1. 39
      src/Generator/CodeGenerator.cs
  2. 17
      src/Parser/Parser.cpp

39
src/Generator/CodeGenerator.cs

@ -26,41 +26,36 @@ namespace Cxxi @@ -26,41 +26,36 @@ namespace Cxxi
{
library = new Library(options.OutputNamespace, options.LibraryName);
var parserOptions = new ParserOptions
{
Library = library,
Verbose = false,
IncludeDirs = options.IncludeDirs
};
Console.WriteLine("Parsing code...");
foreach (var file in options.Headers)
{
string path;
var headers = new List<string>();
transform.SetupHeaders(headers);
try
{
path = Path.GetFullPath(file);
}
catch (ArgumentException)
{
Console.WriteLine("Invalid path '" + file + "'.");
continue;
foreach (var header in headers)
ParseHeader(header);
foreach (var header in options.Headers)
ParseHeader(header);
}
var module = new TranslationUnit(path);
parserOptions.FileName = path;
void ParseHeader(string file)
{
var parserOptions = new ParserOptions
{
Library = library,
Verbose = false,
IncludeDirs = options.IncludeDirs,
FileName = file
};
if (!ClangParser.Parse(parserOptions))
{
Console.WriteLine(" Could not parse '" + file + "'.");
continue;
return;
}
Console.WriteLine(" Parsed '" + file + "'.");
}
}
public void ProcessCode()
{

17
src/Parser/Parser.cpp

@ -19,6 +19,8 @@ @@ -19,6 +19,8 @@
#include <clang/Driver/Util.h>
#include <string>
#include <iostream>
#include <sstream>
//-----------------------------------//
@ -1315,16 +1317,15 @@ bool Parser::Parse(const std::string& File) @@ -1315,16 +1317,15 @@ bool Parser::Parse(const std::string& File)
C->setASTConsumer(new ParseConsumer());
// Get the file from the file system
const clang::FileEntry* file = C->getFileManager().getFile(File.c_str());
// Create a virtual file that includes the header. This gets rid of some
// Clang warnings about parsing an header file as the main file.
if (!file)
{
Debug("Filename '%s' was not found.\n", File.c_str());
return false;
}
std::string str;
str += "#include \"" + File + "\"" + "\n";
str += "\0";
C->getSourceManager().createMainFileID(file);
auto buffer = llvm::MemoryBuffer::getMemBuffer(str);
C->getSourceManager().createMainFileIDForMemBuffer(buffer);
clang::DiagnosticConsumer* client = C->getDiagnostics().getClient();
client->BeginSourceFile(C->getLangOpts(), &C->getPreprocessor());

Loading…
Cancel
Save