blob: 59798f124a35fc44106a96d9b04b8e6c38610b79 [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
Chris Lattner38ba3362006-08-17 07:04:37 +000033 // Initialize the parser.
34 P.Initialize();
Chris Lattner73709ed2006-08-17 06:28:25 +000035 }
36
37 /// ReadTopLevelDecl - Parse and return the next top-level declaration.
38 Decl *ReadTopLevelDecl() {
Chris Lattner38ba3362006-08-17 07:04:37 +000039 Parser::DeclTy *Result;
40 if (P.ParseTopLevelDecl(Result))
41 return 0;
42 Result = (Decl*)1; // FIXME!
43 return (Decl*)Result;
44 }
45
46 ~ASTStreamer() {
47 P.Finalize();
Chris Lattner73709ed2006-08-17 06:28:25 +000048 }
49 };
50}
51
52
53
54//===----------------------------------------------------------------------===//
55// Public interface to the file
56//===----------------------------------------------------------------------===//
57
58/// ASTStreamer_Init - Create an ASTStreamer with the specified preprocessor
59/// and FileID.
60ASTStreamerTy *llvm::clang::ASTStreamer_Init(Preprocessor &PP,
61 unsigned MainFileID) {
62 return new ASTStreamer(PP, MainFileID);
63}
64
65/// ASTStreamer_ReadTopLevelDecl - Parse and return one top-level declaration. This
66/// returns null at end of file.
67Decl *llvm::clang::ASTStreamer_ReadTopLevelDecl(ASTStreamerTy *Streamer) {
68 return static_cast<ASTStreamer*>(Streamer)->ReadTopLevelDecl();
69}
70
71/// ASTStreamer_Terminate - Gracefully shut down the streamer.
72///
73void llvm::clang::ASTStreamer_Terminate(ASTStreamerTy *Streamer) {
74 delete static_cast<ASTStreamer*>(Streamer);
75}