diff options
| author | Chris Lattner <sabre@nondot.org> | 2006-08-17 05:51:27 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2006-08-17 05:51:27 +0000 |
| commit | 3e7bd4ed4457efb721a54faacfb4593f06922715 (patch) | |
| tree | 88d731db535c39767922f387f713c13af0ef326b /clang/Driver/PrintParserCallbacks.cpp | |
| parent | eb401b1bc76ebfc3b86ea9f08959d6ca50fc0ca9 (diff) | |
| download | bcm5719-llvm-3e7bd4ed4457efb721a54faacfb4593f06922715.tar.gz bcm5719-llvm-3e7bd4ed4457efb721a54faacfb4593f06922715.zip | |
Start adding support for printing out parser callbacks and adding ast building
llvm-svn: 38933
Diffstat (limited to 'clang/Driver/PrintParserCallbacks.cpp')
| -rw-r--r-- | clang/Driver/PrintParserCallbacks.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/clang/Driver/PrintParserCallbacks.cpp b/clang/Driver/PrintParserCallbacks.cpp new file mode 100644 index 00000000000..9f10fb5cc17 --- /dev/null +++ b/clang/Driver/PrintParserCallbacks.cpp @@ -0,0 +1,57 @@ +//===--- 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/Declarations.h" +#include <iostream> + +using namespace llvm; +using namespace clang; + +namespace { + class ParserPrintActions : public EmptyAction { + + /// ParseDeclarator - 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 void ParseDeclarator(SourceLocation Loc, Scope *S, Declarator &D, + ExprTy *Init) { + std::cout << "ParseDeclarator "; + 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. + EmptyAction::ParseDeclarator(Loc, S, D, Init); + } + + /// 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. + EmptyAction::PopScope(Loc, S); + } + }; +} + +Action *llvm::clang::CreatePrintParserActionsAction() { + return new ParserPrintActions(); +} |

