diff options
-rw-r--r-- | clang/AST/ASTStreamer.cpp | 67 | ||||
-rw-r--r-- | clang/Driver/clang.cpp | 20 | ||||
-rw-r--r-- | clang/Makefile | 2 | ||||
-rw-r--r-- | clang/Sema/ASTStreamer.cpp | 67 | ||||
-rw-r--r-- | clang/clang.xcodeproj/project.pbxproj | 8 | ||||
-rw-r--r-- | clang/include/clang/AST/AST.h | 12 | ||||
-rw-r--r-- | clang/include/clang/AST/ASTStreamer.h | 41 | ||||
-rw-r--r-- | clang/include/clang/AST/Decl.h | 2 | ||||
-rw-r--r-- | clang/include/clang/Sema/ASTStreamer.h | 41 |
9 files changed, 244 insertions, 16 deletions
diff --git a/clang/AST/ASTStreamer.cpp b/clang/AST/ASTStreamer.cpp new file mode 100644 index 00000000000..77436cf10ee --- /dev/null +++ b/clang/AST/ASTStreamer.cpp @@ -0,0 +1,67 @@ +//===--- ASTStreamer.cpp - Provide streaming interface to ASTs ------------===// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by Chris Lattner and is distributed under +// the University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file implements the ASTStreamer interface. +// +//===----------------------------------------------------------------------===// + +#include "clang/AST/ASTStreamer.h" +#include "clang/Parse/Action.h" +#include "clang/Parse/Parser.h" + +using namespace llvm; +using namespace clang; + + + + +namespace { + class ASTStreamer { + EmptyAction Builder; + Parser P; + public: + ASTStreamer(Preprocessor &PP, unsigned MainFileID) + : P(PP, Builder) { + PP.EnterSourceFile(MainFileID, 0, true); + + // Parsing the specified input file. + P.ParseTranslationUnit(); + } + + /// ReadTopLevelDecl - Parse and return the next top-level declaration. + Decl *ReadTopLevelDecl() { + return 0; + } + }; +} + + + +//===----------------------------------------------------------------------===// +// Public interface to the file +//===----------------------------------------------------------------------===// + +/// ASTStreamer_Init - Create an ASTStreamer with the specified preprocessor +/// and FileID. +ASTStreamerTy *llvm::clang::ASTStreamer_Init(Preprocessor &PP, + unsigned MainFileID) { + return new ASTStreamer(PP, MainFileID); +} + +/// ASTStreamer_ReadTopLevelDecl - Parse and return one top-level declaration. This +/// returns null at end of file. +Decl *llvm::clang::ASTStreamer_ReadTopLevelDecl(ASTStreamerTy *Streamer) { + return static_cast<ASTStreamer*>(Streamer)->ReadTopLevelDecl(); +} + +/// ASTStreamer_Terminate - Gracefully shut down the streamer. +/// +void llvm::clang::ASTStreamer_Terminate(ASTStreamerTy *Streamer) { + delete static_cast<ASTStreamer*>(Streamer); +} diff --git a/clang/Driver/clang.cpp b/clang/Driver/clang.cpp index d736e48d6f5..9f3810eedc9 100644 --- a/clang/Driver/clang.cpp +++ b/clang/Driver/clang.cpp @@ -616,20 +616,30 @@ static void ReadPrologFiles(Preprocessor &PP, std::vector<char> &Buf) { } //===----------------------------------------------------------------------===// -// Parser driver +// Basic Parser driver //===----------------------------------------------------------------------===// static void ParseFile(Preprocessor &PP, Action *PA, unsigned MainFileID) { Parser P(PP, *PA); - PP.EnterSourceFile(MainFileID, 0, true); + // Parsing the specified input file. P.ParseTranslationUnit(); + delete PA; +} - // Start parsing the specified input file. +//===----------------------------------------------------------------------===// +// ASTStreamer drivers +//===----------------------------------------------------------------------===// +static void PrintASTs(Preprocessor &PP, unsigned MainFileID) { + ASTStreamerTy *Streamer = ASTStreamer_Init(PP, MainFileID); - delete PA; + while (Decl *D = ASTStreamer_ReadTopLevelDecl(Streamer)) { + std::cerr << "Read decl!\n"; + } + + ASTStreamer_Terminate(Streamer); } //===----------------------------------------------------------------------===// @@ -757,7 +767,7 @@ int main(int argc, char **argv) { ParseFile(PP, CreatePrintParserActionsAction(), MainFileID); break; case ParsePrintASTs: - // + PrintASTs(PP, MainFileID); break; case ParseSyntaxOnly: // -fsyntax-only ParseFile(PP, new EmptyAction(), MainFileID); diff --git a/clang/Makefile b/clang/Makefile index 9c1f7a2d42d..c559a3cffa8 100644 --- a/clang/Makefile +++ b/clang/Makefile @@ -6,6 +6,6 @@ CXXFLAGS = -fno-rtti -fno-exceptions TOOLNAME = clang -USEDLIBS = clangParse.a clangLex.a clangBasic.a LLVMSupport.a LLVMSystem.a +USEDLIBS = clangAST.a clangParse.a clangLex.a clangBasic.a LLVMSupport.a LLVMSystem.a include $(LEVEL)/Makefile.common diff --git a/clang/Sema/ASTStreamer.cpp b/clang/Sema/ASTStreamer.cpp new file mode 100644 index 00000000000..77436cf10ee --- /dev/null +++ b/clang/Sema/ASTStreamer.cpp @@ -0,0 +1,67 @@ +//===--- ASTStreamer.cpp - Provide streaming interface to ASTs ------------===// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by Chris Lattner and is distributed under +// the University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file implements the ASTStreamer interface. +// +//===----------------------------------------------------------------------===// + +#include "clang/AST/ASTStreamer.h" +#include "clang/Parse/Action.h" +#include "clang/Parse/Parser.h" + +using namespace llvm; +using namespace clang; + + + + +namespace { + class ASTStreamer { + EmptyAction Builder; + Parser P; + public: + ASTStreamer(Preprocessor &PP, unsigned MainFileID) + : P(PP, Builder) { + PP.EnterSourceFile(MainFileID, 0, true); + + // Parsing the specified input file. + P.ParseTranslationUnit(); + } + + /// ReadTopLevelDecl - Parse and return the next top-level declaration. + Decl *ReadTopLevelDecl() { + return 0; + } + }; +} + + + +//===----------------------------------------------------------------------===// +// Public interface to the file +//===----------------------------------------------------------------------===// + +/// ASTStreamer_Init - Create an ASTStreamer with the specified preprocessor +/// and FileID. +ASTStreamerTy *llvm::clang::ASTStreamer_Init(Preprocessor &PP, + unsigned MainFileID) { + return new ASTStreamer(PP, MainFileID); +} + +/// ASTStreamer_ReadTopLevelDecl - Parse and return one top-level declaration. This +/// returns null at end of file. +Decl *llvm::clang::ASTStreamer_ReadTopLevelDecl(ASTStreamerTy *Streamer) { + return static_cast<ASTStreamer*>(Streamer)->ReadTopLevelDecl(); +} + +/// ASTStreamer_Terminate - Gracefully shut down the streamer. +/// +void llvm::clang::ASTStreamer_Terminate(ASTStreamerTy *Streamer) { + delete static_cast<ASTStreamer*>(Streamer); +} diff --git a/clang/clang.xcodeproj/project.pbxproj b/clang/clang.xcodeproj/project.pbxproj index 1b448893892..45d49e2acd2 100644 --- a/clang/clang.xcodeproj/project.pbxproj +++ b/clang/clang.xcodeproj/project.pbxproj @@ -27,6 +27,8 @@ DEC8D9A40A94346E00353FCA /* AST.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DEC8D9A30A94346E00353FCA /* AST.h */; }; DEC8D9B60A9434FA00353FCA /* Builder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DEC8D9B50A9434FA00353FCA /* Builder.cpp */; }; DEC8DA1E0A94388B00353FCA /* PrintParserCallbacks.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DEC8DA1D0A94388B00353FCA /* PrintParserCallbacks.cpp */; }; + DEC8DAAD0A94400300353FCA /* ASTStreamer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DEC8DAAC0A94400300353FCA /* ASTStreamer.cpp */; }; + DEC8DAC00A94402500353FCA /* ASTStreamer.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DEC8DABF0A94402500353FCA /* ASTStreamer.h */; }; DED7D72D0A524281003AD0FB /* clang.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DED7D72C0A524281003AD0FB /* clang.cpp */; }; DED7D7410A524295003AD0FB /* Diagnostic.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DED7D7310A524295003AD0FB /* Diagnostic.h */; }; DED7D7420A524295003AD0FB /* DiagnosticKinds.def in CopyFiles */ = {isa = PBXBuildFile; fileRef = DED7D7320A524295003AD0FB /* DiagnosticKinds.def */; }; @@ -109,6 +111,7 @@ DE06E8140A8FF9330050E87E /* Action.h in CopyFiles */, DEC8D9910A9433CD00353FCA /* Decl.h in CopyFiles */, DEC8D9A40A94346E00353FCA /* AST.h in CopyFiles */, + DEC8DAC00A94402500353FCA /* ASTStreamer.h in CopyFiles */, ); runOnlyForDeploymentPostprocessing = 1; }; @@ -136,6 +139,8 @@ DEC8D9A30A94346E00353FCA /* AST.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = AST.h; path = clang/AST/AST.h; sourceTree = "<group>"; }; DEC8D9B50A9434FA00353FCA /* Builder.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = Builder.cpp; path = AST/Builder.cpp; sourceTree = "<group>"; }; DEC8DA1D0A94388B00353FCA /* PrintParserCallbacks.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = PrintParserCallbacks.cpp; sourceTree = "<group>"; }; + DEC8DAAC0A94400300353FCA /* ASTStreamer.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ASTStreamer.cpp; path = AST/ASTStreamer.cpp; sourceTree = "<group>"; }; + DEC8DABF0A94402500353FCA /* ASTStreamer.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ASTStreamer.h; path = clang/AST/ASTStreamer.h; sourceTree = "<group>"; }; DED7D72C0A524281003AD0FB /* clang.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = clang.cpp; sourceTree = "<group>"; }; DED7D7310A524295003AD0FB /* Diagnostic.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = Diagnostic.h; sourceTree = "<group>"; }; DED7D7320A524295003AD0FB /* DiagnosticKinds.def */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = DiagnosticKinds.def; sourceTree = "<group>"; }; @@ -260,6 +265,7 @@ isa = PBXGroup; children = ( DEC8D9A30A94346E00353FCA /* AST.h */, + DEC8DABF0A94402500353FCA /* ASTStreamer.h */, DEC8D9900A9433CD00353FCA /* Decl.h */, ); name = AST; @@ -268,6 +274,7 @@ DEC8D9920A9433F400353FCA /* AST */ = { isa = PBXGroup; children = ( + DEC8DAAC0A94400300353FCA /* ASTStreamer.cpp */, DEC8D9B50A9434FA00353FCA /* Builder.cpp */, ); name = AST; @@ -418,6 +425,7 @@ DE06E4D70A8FBF7A0050E87E /* Initializer.cpp in Sources */, DEC8D9B60A9434FA00353FCA /* Builder.cpp in Sources */, DEC8DA1E0A94388B00353FCA /* PrintParserCallbacks.cpp in Sources */, + DEC8DAAD0A94400300353FCA /* ASTStreamer.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/clang/include/clang/AST/AST.h b/clang/include/clang/AST/AST.h index 36ce960328c..507df3e0077 100644 --- a/clang/include/clang/AST/AST.h +++ b/clang/include/clang/AST/AST.h @@ -14,14 +14,8 @@ #ifndef LLVM_CLANG_AST_AST_H #define LLVM_CLANG_AST_AST_H -namespace llvm { -namespace clang { - - class Action; - - - -} // end namespace clang -} // end namespace llvm +// This header exports all AST interfaces. +#include "clang/AST/ASTStreamer.h" +#include "clang/AST/Decl.h" #endif diff --git a/clang/include/clang/AST/ASTStreamer.h b/clang/include/clang/AST/ASTStreamer.h new file mode 100644 index 00000000000..21e3addf1a9 --- /dev/null +++ b/clang/include/clang/AST/ASTStreamer.h @@ -0,0 +1,41 @@ +//===--- AST.h - "Umbrella" header for AST library --------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by Chris Lattner and is distributed under +// the University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines the ASTStreamer interface. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_AST_ASTSTREAMER_H +#define LLVM_CLANG_AST_ASTSTREAMER_H + +namespace llvm { +namespace clang { + class Preprocessor; + class Decl; + + /// ASTStreamerTy - This is an opaque type used to reference ASTStreamer + /// objects. + typedef void ASTStreamerTy; + + /// ASTStreamer_Init - Create an ASTStreamer with the specified preprocessor + /// and FileID. + ASTStreamerTy *ASTStreamer_Init(Preprocessor &PP, unsigned MainFileID); + + /// ASTStreamer_ReadTopLevelDecl - Parse and return one top-level declaration. This + /// returns null at end of file. + Decl *ASTStreamer_ReadTopLevelDecl(ASTStreamerTy *Streamer); + + /// ASTStreamer_Terminate - Gracefully shut down the streamer. + /// + void ASTStreamer_Terminate(ASTStreamerTy *Streamer); + +} // end namespace clang +} // end namespace llvm + +#endif
\ No newline at end of file diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h index 2ef3272fa19..3a07d99a8e6 100644 --- a/clang/include/clang/AST/Decl.h +++ b/clang/include/clang/AST/Decl.h @@ -14,7 +14,7 @@ #ifndef LLVM_CLANG_AST_DECL_H #define LLVM_CLANG_AST_DECL_H -#include "clang/ADT/SourceLocation.h" +#include "clang/Basic/SourceLocation.h" namespace llvm { namespace clang { diff --git a/clang/include/clang/Sema/ASTStreamer.h b/clang/include/clang/Sema/ASTStreamer.h new file mode 100644 index 00000000000..21e3addf1a9 --- /dev/null +++ b/clang/include/clang/Sema/ASTStreamer.h @@ -0,0 +1,41 @@ +//===--- AST.h - "Umbrella" header for AST library --------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by Chris Lattner and is distributed under +// the University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines the ASTStreamer interface. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_AST_ASTSTREAMER_H +#define LLVM_CLANG_AST_ASTSTREAMER_H + +namespace llvm { +namespace clang { + class Preprocessor; + class Decl; + + /// ASTStreamerTy - This is an opaque type used to reference ASTStreamer + /// objects. + typedef void ASTStreamerTy; + + /// ASTStreamer_Init - Create an ASTStreamer with the specified preprocessor + /// and FileID. + ASTStreamerTy *ASTStreamer_Init(Preprocessor &PP, unsigned MainFileID); + + /// ASTStreamer_ReadTopLevelDecl - Parse and return one top-level declaration. This + /// returns null at end of file. + Decl *ASTStreamer_ReadTopLevelDecl(ASTStreamerTy *Streamer); + + /// ASTStreamer_Terminate - Gracefully shut down the streamer. + /// + void ASTStreamer_Terminate(ASTStreamerTy *Streamer); + +} // end namespace clang +} // end namespace llvm + +#endif
\ No newline at end of file |