2006-08-17 13:51:27 +08:00
|
|
|
//===--- 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/Parse/Action.h"
|
2006-11-12 07:03:42 +08:00
|
|
|
#include "clang/Parse/DeclSpec.h"
|
2006-08-17 13:51:27 +08:00
|
|
|
#include <iostream>
|
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
namespace {
|
2006-11-06 02:44:26 +08:00
|
|
|
class ParserPrintActions : public MinimalAction {
|
2006-08-17 13:51:27 +08:00
|
|
|
|
2007-09-16 02:49:24 +08:00
|
|
|
/// ActOnDeclarator - This callback is invoked when a declarator is parsed
|
2006-10-16 08:33:54 +08:00
|
|
|
/// and 'Init' specifies the initializer if any. This is for things like:
|
2006-08-17 13:51:27 +08:00
|
|
|
/// "int X = 4" or "typedef int foo".
|
2007-09-16 02:49:24 +08:00
|
|
|
virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D,
|
2006-10-16 08:33:54 +08:00
|
|
|
DeclTy *LastInGroup) {
|
2007-09-16 02:49:24 +08:00
|
|
|
std::cout << "ActOnDeclarator ";
|
2006-08-17 13:51:27 +08:00
|
|
|
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.
|
2007-09-16 02:49:24 +08:00
|
|
|
return MinimalAction::ActOnDeclarator(S, D, LastInGroup);
|
2006-08-17 13:51:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// 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.
|
2006-11-06 02:44:26 +08:00
|
|
|
MinimalAction::PopScope(Loc, S);
|
2006-08-17 13:51:27 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2007-06-16 07:05:46 +08:00
|
|
|
MinimalAction *clang::CreatePrintParserActionsAction() {
|
2006-08-17 13:51:27 +08:00
|
|
|
return new ParserPrintActions();
|
|
|
|
}
|