llvm-project/clang/Driver/PrintParserCallbacks.cpp
Steve Naroff 30d242c99f Start converting Action methods from Parse-prefix to ActOn-prefix.
The previous naming scheme was confusing, since it resulted in both the Parser and Action modules having methods with the same name. In addition, the Action module never does any parsing...

llvm-svn: 41986
2007-09-15 18:49:24 +00:00

56 lines
1.9 KiB
C++

//===--- PrintParserActions.cpp - Implement -parse-print-callbacks mode ---===//
//
// The LLVM Compiler Infrastructure
//
// This file was developed by Chris Lattner and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This code simply runs the preprocessor on the input file and prints out the
// result. This is the traditional behavior of the -E option.
//
//===----------------------------------------------------------------------===//
#include "clang.h"
#include "clang/Lex/IdentifierTable.h"
#include "clang/Parse/Action.h"
#include "clang/Parse/DeclSpec.h"
#include <iostream>
using namespace clang;
namespace {
class ParserPrintActions : public MinimalAction {
/// ActOnDeclarator - This callback is invoked when a declarator is parsed
/// and 'Init' specifies the initializer if any. This is for things like:
/// "int X = 4" or "typedef int foo".
virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D,
DeclTy *LastInGroup) {
std::cout << "ActOnDeclarator ";
if (IdentifierInfo *II = D.getIdentifier()) {
std::cout << "'" << II->getName() << "'";
} else {
std::cout << "<anon>";
}
std::cout << "\n";
// Pass up to EmptyActions so that the symbol table is maintained right.
return MinimalAction::ActOnDeclarator(S, D, LastInGroup);
}
/// PopScope - This callback is called immediately before the specified scope
/// is popped and deleted.
virtual void PopScope(SourceLocation Loc, Scope *S) {
std::cout << "PopScope\n";
// Pass up to EmptyActions so that the symbol table is maintained right.
MinimalAction::PopScope(Loc, S);
}
};
}
MinimalAction *clang::CreatePrintParserActionsAction() {
return new ParserPrintActions();
}