blob: d7deb43f87ace8c49593cddfcc84a99e751dd488 [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//
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 Spencer5f016e22007-07-11 17:01:13 +000016#include "clang/Parse/Action.h"
17#include "clang/Parse/DeclSpec.h"
18#include <iostream>
19using namespace clang;
20
21namespace {
22 class ParserPrintActions : public MinimalAction {
23
Steve Naroff08d92e42007-09-15 18:49:24 +000024 /// ActOnDeclarator - This callback is invoked when a declarator is parsed
Reid Spencer5f016e22007-07-11 17:01:13 +000025 /// and 'Init' specifies the initializer if any. This is for things like:
26 /// "int X = 4" or "typedef int foo".
Steve Naroff08d92e42007-09-15 18:49:24 +000027 virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D,
Reid Spencer5f016e22007-07-11 17:01:13 +000028 DeclTy *LastInGroup) {
Steve Naroff08d92e42007-09-15 18:49:24 +000029 std::cout << "ActOnDeclarator ";
Reid Spencer5f016e22007-07-11 17:01:13 +000030 if (IdentifierInfo *II = D.getIdentifier()) {
31 std::cout << "'" << II->getName() << "'";
32 } else {
33 std::cout << "<anon>";
34 }
35 std::cout << "\n";
36
37 // Pass up to EmptyActions so that the symbol table is maintained right.
Steve Naroff08d92e42007-09-15 18:49:24 +000038 return MinimalAction::ActOnDeclarator(S, D, LastInGroup);
Reid Spencer5f016e22007-07-11 17:01:13 +000039 }
40
Steve Naroff640db422007-10-10 17:45:44 +000041 /// ActOnPopScope - This callback is called immediately before the specified
42 /// scope is popped and deleted.
43 virtual void ActOnPopScope(SourceLocation Loc, Scope *S) {
44 std::cout << "ActOnPopScope\n";
Reid Spencer5f016e22007-07-11 17:01:13 +000045
46 // Pass up to EmptyActions so that the symbol table is maintained right.
Steve Naroff640db422007-10-10 17:45:44 +000047 MinimalAction::ActOnPopScope(Loc, S);
Reid Spencer5f016e22007-07-11 17:01:13 +000048 }
49 };
50}
51
52MinimalAction *clang::CreatePrintParserActionsAction() {
53 return new ParserPrintActions();
54}