blob: e3bfdf57f1de9c7f670541a3da44c8e16a7163ad [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"
Chris Lattner3e7bd4e2006-08-17 05:51:27 +000016#include "clang/Parse/Action.h"
Chris Lattner288e86ff12006-11-11 23:03:42 +000017#include "clang/Parse/DeclSpec.h"
Chris Lattner3e7bd4e2006-08-17 05:51:27 +000018#include <iostream>
Chris Lattner3e7bd4e2006-08-17 05:51:27 +000019using namespace clang;
20
21namespace {
Chris Lattnerc62b6c22006-11-05 18:44:26 +000022 class ParserPrintActions : public MinimalAction {
Chris Lattner3e7bd4e2006-08-17 05:51:27 +000023
Steve Naroff30d242c2007-09-15 18:49:24 +000024 /// ActOnDeclarator - This callback is invoked when a declarator is parsed
Chris Lattner2dacc3f2006-10-16 00:33:54 +000025 /// and 'Init' specifies the initializer if any. This is for things like:
Chris Lattner3e7bd4e2006-08-17 05:51:27 +000026 /// "int X = 4" or "typedef int foo".
Steve Naroff30d242c2007-09-15 18:49:24 +000027 virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D,
Chris Lattner2dacc3f2006-10-16 00:33:54 +000028 DeclTy *LastInGroup) {
Steve Naroff30d242c2007-09-15 18:49:24 +000029 std::cout << "ActOnDeclarator ";
Chris Lattner3e7bd4e2006-08-17 05:51:27 +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 Naroff30d242c2007-09-15 18:49:24 +000038 return MinimalAction::ActOnDeclarator(S, D, LastInGroup);
Chris Lattner3e7bd4e2006-08-17 05:51:27 +000039 }
40
41 /// PopScope - This callback is called immediately before the specified scope
42 /// is popped and deleted.
43 virtual void PopScope(SourceLocation Loc, Scope *S) {
44 std::cout << "PopScope\n";
45
46 // Pass up to EmptyActions so that the symbol table is maintained right.
Chris Lattnerc62b6c22006-11-05 18:44:26 +000047 MinimalAction::PopScope(Loc, S);
Chris Lattner3e7bd4e2006-08-17 05:51:27 +000048 }
49 };
50}
51
Chris Lattner23b7eb62007-06-15 23:05:46 +000052MinimalAction *clang::CreatePrintParserActionsAction() {
Chris Lattner3e7bd4e2006-08-17 05:51:27 +000053 return new ParserPrintActions();
54}