[cfe-dev] Parse error on //*
Magnus Reftel
magnus.reftel at gmail.com
Thu Mar 18 06:56:36 PDT 2010
Hi all,
I'm trying to build a simple source code transformation tool. I'm
having problems getting the parser to accept single-line comments that
start with an asterisk. Even a file containing only the three
characters "//*" fails, while one with "// *" succeeds. The error I
get is
comment.c:1:1: error: expected identifier or '('
followed by an assertion failure I get on any diagnostic (setting
breakpoints reveals that TextDiagnosticPrinter::BeginSourceFile never
gets called, which is probably related):
assertion "LangOpts && "Unexpected diagnostic outside source file
processing"" failed: file "TextDiagnosticPrinter.cpp", line 282,
function: void clang::TextDiagnosticPrinter::EmitCaretDiagnostic(clang::SourceLocation,
clang::SourceRange*, unsigned int, clang::SourceManager&, const
clang::CodeModificationHint*, unsigned int, unsigned int)
Stack dump:
0. comment.c:1:1: current parser token '/'
Aborted
Funny thing is, Lexer/c90.c passes. I've minimized my program to the
code below. I've tried to explicitly set C99 to 1 in the LangOptions,
but with no success. I'm using revision 98818 on Cygwin. Any ideas of
what goes wrong?
Best regards
Magnus Reftel
#include <clang/AST/ASTConsumer.h>
#include <clang/AST/ASTContext.h>
#include <clang/Basic/Diagnostic.h>
#include <clang/Basic/FileManager.h>
#include <clang/Basic/SourceManager.h>
#include <clang/Basic/TargetInfo.h>
#include <clang/Basic/TargetOptions.h>
#include <clang/Frontend/DiagnosticOptions.h>
#include <clang/Frontend/TextDiagnosticPrinter.h>
#include <clang/Lex/HeaderSearch.h>
#include <clang/Lex/Preprocessor.h>
#include <clang/Sema/ParseAST.h>
#include <llvm/Config/config.h>
#include <llvm/Support/raw_ostream.h>
using namespace clang;
int main(int argc, char* argv[])
{
llvm::raw_ostream* ostream=new llvm::raw_stderr_ostream();
DiagnosticOptions diagnostic_options=DiagnosticOptions();
DiagnosticClient* diag_client=new TextDiagnosticPrinter(
*ostream, diagnostic_options, false
);
Diagnostic diagnostic=Diagnostic(diag_client);
LangOptions options=LangOptions();
TargetOptions target_options=TargetOptions();
target_options.Triple=LLVM_HOSTTRIPLE;
TargetInfo* target_info=TargetInfo::CreateTargetInfo(
diagnostic, target_options
);
SourceManager source_manager(diagnostic);
FileManager file_manager;
HeaderSearch header_search(file_manager);
Preprocessor preprocessor(
diagnostic, options, *target_info, source_manager,
header_search
);
const FileEntry* file=file_manager.getFile("comment.c");
source_manager.createMainFileID(file, SourceLocation());
ASTConsumer print_globals;
IdentifierTable identifier_table(options);
SelectorTable selector_table;
Builtin::Context builtins=Builtin::Context(*target_info);
ASTContext context(
options, source_manager, *target_info, identifier_table,
selector_table, builtins
);
ParseAST(preprocessor, &print_globals, context);
delete target_info;
delete diag_client;
delete ostream;
return 0;
}
More information about the cfe-dev
mailing list