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" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 16 | #include "clang/Parse/Action.h" |
| 17 | #include "clang/Parse/DeclSpec.h" |
| 18 | #include <iostream> |
| 19 | using namespace clang; |
| 20 | |
| 21 | namespace { |
| 22 | class ParserPrintActions : public MinimalAction { |
| 23 | |
Steve Naroff | b4292f2 | 2007-10-31 20:55:39 +0000 | [diff] [blame^] | 24 | public: |
| 25 | ParserPrintActions(IdentifierTable &IT) : MinimalAction(IT) {} |
| 26 | |
Steve Naroff | 08d92e4 | 2007-09-15 18:49:24 +0000 | [diff] [blame] | 27 | /// ActOnDeclarator - This callback is invoked when a declarator is parsed |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 28 | /// and 'Init' specifies the initializer if any. This is for things like: |
| 29 | /// "int X = 4" or "typedef int foo". |
Steve Naroff | 08d92e4 | 2007-09-15 18:49:24 +0000 | [diff] [blame] | 30 | virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D, |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 31 | DeclTy *LastInGroup) { |
Steve Naroff | 08d92e4 | 2007-09-15 18:49:24 +0000 | [diff] [blame] | 32 | std::cout << "ActOnDeclarator "; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 33 | if (IdentifierInfo *II = D.getIdentifier()) { |
| 34 | std::cout << "'" << II->getName() << "'"; |
| 35 | } else { |
| 36 | std::cout << "<anon>"; |
| 37 | } |
| 38 | std::cout << "\n"; |
| 39 | |
| 40 | // Pass up to EmptyActions so that the symbol table is maintained right. |
Steve Naroff | 08d92e4 | 2007-09-15 18:49:24 +0000 | [diff] [blame] | 41 | return MinimalAction::ActOnDeclarator(S, D, LastInGroup); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Steve Naroff | 640db42 | 2007-10-10 17:45:44 +0000 | [diff] [blame] | 44 | /// ActOnPopScope - This callback is called immediately before the specified |
| 45 | /// scope is popped and deleted. |
| 46 | virtual void ActOnPopScope(SourceLocation Loc, Scope *S) { |
| 47 | std::cout << "ActOnPopScope\n"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 48 | |
| 49 | // Pass up to EmptyActions so that the symbol table is maintained right. |
Steve Naroff | 640db42 | 2007-10-10 17:45:44 +0000 | [diff] [blame] | 50 | MinimalAction::ActOnPopScope(Loc, S); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 51 | } |
| 52 | }; |
| 53 | } |
| 54 | |
Steve Naroff | b4292f2 | 2007-10-31 20:55:39 +0000 | [diff] [blame^] | 55 | MinimalAction *clang::CreatePrintParserActionsAction(IdentifierTable &IT) { |
| 56 | return new ParserPrintActions(IT); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 57 | } |