Chris Lattner | 3e7bd4e | 2006-08-17 05:51:27 +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" |
Chris Lattner | 3e7bd4e | 2006-08-17 05:51:27 +0000 | [diff] [blame] | 16 | #include "clang/Parse/Action.h" |
Chris Lattner | 288e86ff1 | 2006-11-11 23:03:42 +0000 | [diff] [blame] | 17 | #include "clang/Parse/DeclSpec.h" |
Chris Lattner | 3e7bd4e | 2006-08-17 05:51:27 +0000 | [diff] [blame] | 18 | #include <iostream> |
Chris Lattner | 3e7bd4e | 2006-08-17 05:51:27 +0000 | [diff] [blame] | 19 | using namespace clang; |
| 20 | |
| 21 | namespace { |
Chris Lattner | c62b6c2 | 2006-11-05 18:44:26 +0000 | [diff] [blame] | 22 | class ParserPrintActions : public MinimalAction { |
Chris Lattner | 3e7bd4e | 2006-08-17 05:51:27 +0000 | [diff] [blame] | 23 | |
Steve Naroff | aaba027 | 2007-10-31 20:55:39 +0000 | [diff] [blame^] | 24 | public: |
| 25 | ParserPrintActions(IdentifierTable &IT) : MinimalAction(IT) {} |
| 26 | |
Steve Naroff | 30d242c | 2007-09-15 18:49:24 +0000 | [diff] [blame] | 27 | /// ActOnDeclarator - This callback is invoked when a declarator is parsed |
Chris Lattner | 2dacc3f | 2006-10-16 00:33:54 +0000 | [diff] [blame] | 28 | /// and 'Init' specifies the initializer if any. This is for things like: |
Chris Lattner | 3e7bd4e | 2006-08-17 05:51:27 +0000 | [diff] [blame] | 29 | /// "int X = 4" or "typedef int foo". |
Steve Naroff | 30d242c | 2007-09-15 18:49:24 +0000 | [diff] [blame] | 30 | virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D, |
Chris Lattner | 2dacc3f | 2006-10-16 00:33:54 +0000 | [diff] [blame] | 31 | DeclTy *LastInGroup) { |
Steve Naroff | 30d242c | 2007-09-15 18:49:24 +0000 | [diff] [blame] | 32 | std::cout << "ActOnDeclarator "; |
Chris Lattner | 3e7bd4e | 2006-08-17 05:51:27 +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 | 30d242c | 2007-09-15 18:49:24 +0000 | [diff] [blame] | 41 | return MinimalAction::ActOnDeclarator(S, D, LastInGroup); |
Chris Lattner | 3e7bd4e | 2006-08-17 05:51:27 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Steve Naroff | 8308f60 | 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"; |
Chris Lattner | 3e7bd4e | 2006-08-17 05:51:27 +0000 | [diff] [blame] | 48 | |
| 49 | // Pass up to EmptyActions so that the symbol table is maintained right. |
Steve Naroff | 8308f60 | 2007-10-10 17:45:44 +0000 | [diff] [blame] | 50 | MinimalAction::ActOnPopScope(Loc, S); |
Chris Lattner | 3e7bd4e | 2006-08-17 05:51:27 +0000 | [diff] [blame] | 51 | } |
| 52 | }; |
| 53 | } |
| 54 | |
Steve Naroff | aaba027 | 2007-10-31 20:55:39 +0000 | [diff] [blame^] | 55 | MinimalAction *clang::CreatePrintParserActionsAction(IdentifierTable &IT) { |
| 56 | return new ParserPrintActions(IT); |
Chris Lattner | 3e7bd4e | 2006-08-17 05:51:27 +0000 | [diff] [blame] | 57 | } |