blob: 77436cf10eec7aecb74c5f4ba181e3d97328df8e [file] [log] [blame]
Chris Lattner73709ed2006-08-17 06:28:25 +00001//===--- ASTStreamer.cpp - Provide streaming interface to ASTs ------------===//
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 file implements the ASTStreamer interface.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/AST/ASTStreamer.h"
15#include "clang/Parse/Action.h"
16#include "clang/Parse/Parser.h"
17
18using namespace llvm;
19using namespace clang;
20
21
22
23
24namespace {
25 class ASTStreamer {
26 EmptyAction Builder;
27 Parser P;
28 public:
29 ASTStreamer(Preprocessor &PP, unsigned MainFileID)
30 : P(PP, Builder) {
31 PP.EnterSourceFile(MainFileID, 0, true);
32
33 // Parsing the specified input file.
34 P.ParseTranslationUnit();
35 }
36
37 /// ReadTopLevelDecl - Parse and return the next top-level declaration.
38 Decl *ReadTopLevelDecl() {
39 return 0;
40 }
41 };
42}
43
44
45
46//===----------------------------------------------------------------------===//
47// Public interface to the file
48//===----------------------------------------------------------------------===//
49
50/// ASTStreamer_Init - Create an ASTStreamer with the specified preprocessor
51/// and FileID.
52ASTStreamerTy *llvm::clang::ASTStreamer_Init(Preprocessor &PP,
53 unsigned MainFileID) {
54 return new ASTStreamer(PP, MainFileID);
55}
56
57/// ASTStreamer_ReadTopLevelDecl - Parse and return one top-level declaration. This
58/// returns null at end of file.
59Decl *llvm::clang::ASTStreamer_ReadTopLevelDecl(ASTStreamerTy *Streamer) {
60 return static_cast<ASTStreamer*>(Streamer)->ReadTopLevelDecl();
61}
62
63/// ASTStreamer_Terminate - Gracefully shut down the streamer.
64///
65void llvm::clang::ASTStreamer_Terminate(ASTStreamerTy *Streamer) {
66 delete static_cast<ASTStreamer*>(Streamer);
67}