blob: 3e37514bb288705a9d0932f497d7fc64a803c502 [file] [log] [blame]
Chris Lattner3e7bd4e2006-08-17 05:51:27 +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"
16#include "clang/Lex/IdentifierTable.h"
17#include "clang/Parse/Action.h"
Chris Lattner288e86ff12006-11-11 23:03:42 +000018#include "clang/Parse/DeclSpec.h"
Chris Lattner3e7bd4e2006-08-17 05:51:27 +000019#include <iostream>
Chris Lattner3e7bd4e2006-08-17 05:51:27 +000020using namespace clang;
21
22namespace {
Chris Lattnerc62b6c22006-11-05 18:44:26 +000023 class ParserPrintActions : public MinimalAction {
Chris Lattner3e7bd4e2006-08-17 05:51:27 +000024
Chris Lattner2dacc3f2006-10-16 00:33:54 +000025 /// ParseDeclarator - This callback is invoked when a declarator is parsed
26 /// and 'Init' specifies the initializer if any. This is for things like:
Chris Lattner3e7bd4e2006-08-17 05:51:27 +000027 /// "int X = 4" or "typedef int foo".
Steve Naroff61091402007-09-12 14:07:44 +000028 virtual DeclTy *ParseDeclarator(Scope *S, Declarator &D,
Chris Lattner2dacc3f2006-10-16 00:33:54 +000029 DeclTy *LastInGroup) {
Chris Lattner3e7bd4e2006-08-17 05:51:27 +000030 std::cout << "ParseDeclarator ";
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 Naroff61091402007-09-12 14:07:44 +000039 return MinimalAction::ParseDeclarator(S, D, LastInGroup);
Chris Lattner3e7bd4e2006-08-17 05:51:27 +000040 }
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.
Chris Lattnerc62b6c22006-11-05 18:44:26 +000048 MinimalAction::PopScope(Loc, S);
Chris Lattner3e7bd4e2006-08-17 05:51:27 +000049 }
50 };
51}
52
Chris Lattner23b7eb62007-06-15 23:05:46 +000053MinimalAction *clang::CreatePrintParserActionsAction() {
Chris Lattner3e7bd4e2006-08-17 05:51:27 +000054 return new ParserPrintActions();
55}