Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- PrintParserActions.cpp - Implement -parse-print-callbacks mode ---===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by Chris Lattner and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This code simply runs the preprocessor on the input file and prints out the |
| 11 | // result. This is the traditional behavior of the -E option. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "clang.h" |
| 16 | #include "clang/Lex/IdentifierTable.h" |
| 17 | #include "clang/Parse/Action.h" |
| 18 | #include "clang/Parse/DeclSpec.h" |
| 19 | #include <iostream> |
| 20 | using namespace clang; |
| 21 | |
| 22 | namespace { |
| 23 | class ParserPrintActions : public MinimalAction { |
| 24 | |
Steve Naroff | 08d92e4 | 2007-09-15 18:49:24 +0000 | [diff] [blame^] | 25 | /// ActOnDeclarator - This callback is invoked when a declarator is parsed |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 26 | /// and 'Init' specifies the initializer if any. This is for things like: |
| 27 | /// "int X = 4" or "typedef int foo". |
Steve Naroff | 08d92e4 | 2007-09-15 18:49:24 +0000 | [diff] [blame^] | 28 | virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D, |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 29 | DeclTy *LastInGroup) { |
Steve Naroff | 08d92e4 | 2007-09-15 18:49:24 +0000 | [diff] [blame^] | 30 | std::cout << "ActOnDeclarator "; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 31 | if (IdentifierInfo *II = D.getIdentifier()) { |
| 32 | std::cout << "'" << II->getName() << "'"; |
| 33 | } else { |
| 34 | std::cout << "<anon>"; |
| 35 | } |
| 36 | std::cout << "\n"; |
| 37 | |
| 38 | // Pass up to EmptyActions so that the symbol table is maintained right. |
Steve Naroff | 08d92e4 | 2007-09-15 18:49:24 +0000 | [diff] [blame^] | 39 | return MinimalAction::ActOnDeclarator(S, D, LastInGroup); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | /// PopScope - This callback is called immediately before the specified scope |
| 43 | /// is popped and deleted. |
| 44 | virtual void PopScope(SourceLocation Loc, Scope *S) { |
| 45 | std::cout << "PopScope\n"; |
| 46 | |
| 47 | // Pass up to EmptyActions so that the symbol table is maintained right. |
| 48 | MinimalAction::PopScope(Loc, S); |
| 49 | } |
| 50 | }; |
| 51 | } |
| 52 | |
| 53 | MinimalAction *clang::CreatePrintParserActionsAction() { |
| 54 | return new ParserPrintActions(); |
| 55 | } |