blob: 9c67f83aa13f3ee1db4b4d725066dac505a66aea [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- PrintParserActions.cpp - Implement -parse-print-callbacks mode ---===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
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 Spencer5f016e22007-07-11 17:01:13 +000016#include "clang/Parse/Action.h"
17#include "clang/Parse/DeclSpec.h"
Ted Kremenekbdd30c22008-01-14 16:44:48 +000018#include "llvm/Support/Streams.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000019using namespace clang;
20
21namespace {
22 class ParserPrintActions : public MinimalAction {
23
Steve Naroffb4292f22007-10-31 20:55:39 +000024 public:
25 ParserPrintActions(IdentifierTable &IT) : MinimalAction(IT) {}
26
Steve Naroff08d92e42007-09-15 18:49:24 +000027 /// ActOnDeclarator - This callback is invoked when a declarator is parsed
Reid Spencer5f016e22007-07-11 17:01:13 +000028 /// and 'Init' specifies the initializer if any. This is for things like:
29 /// "int X = 4" or "typedef int foo".
Steve Naroff08d92e42007-09-15 18:49:24 +000030 virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D,
Reid Spencer5f016e22007-07-11 17:01:13 +000031 DeclTy *LastInGroup) {
Ted Kremenekbdd30c22008-01-14 16:44:48 +000032 llvm::cout << "ActOnDeclarator ";
Reid Spencer5f016e22007-07-11 17:01:13 +000033 if (IdentifierInfo *II = D.getIdentifier()) {
Ted Kremenekbdd30c22008-01-14 16:44:48 +000034 llvm::cout << "'" << II->getName() << "'";
Reid Spencer5f016e22007-07-11 17:01:13 +000035 } else {
Ted Kremenekbdd30c22008-01-14 16:44:48 +000036 llvm::cout << "<anon>";
Reid Spencer5f016e22007-07-11 17:01:13 +000037 }
Ted Kremenekbdd30c22008-01-14 16:44:48 +000038 llvm::cout << "\n";
Reid Spencer5f016e22007-07-11 17:01:13 +000039
40 // Pass up to EmptyActions so that the symbol table is maintained right.
Steve Naroff08d92e42007-09-15 18:49:24 +000041 return MinimalAction::ActOnDeclarator(S, D, LastInGroup);
Reid Spencer5f016e22007-07-11 17:01:13 +000042 }
43
Steve Naroff640db422007-10-10 17:45:44 +000044 /// ActOnPopScope - This callback is called immediately before the specified
45 /// scope is popped and deleted.
46 virtual void ActOnPopScope(SourceLocation Loc, Scope *S) {
Ted Kremenekbdd30c22008-01-14 16:44:48 +000047 llvm::cout << "ActOnPopScope\n";
Reid Spencer5f016e22007-07-11 17:01:13 +000048
49 // Pass up to EmptyActions so that the symbol table is maintained right.
Steve Naroff640db422007-10-10 17:45:44 +000050 MinimalAction::ActOnPopScope(Loc, S);
Reid Spencer5f016e22007-07-11 17:01:13 +000051 }
52 };
53}
54
Steve Naroffb4292f22007-10-31 20:55:39 +000055MinimalAction *clang::CreatePrintParserActionsAction(IdentifierTable &IT) {
56 return new ParserPrintActions(IT);
Reid Spencer5f016e22007-07-11 17:01:13 +000057}