forked from OSchip/llvm-project
parent
769044337a
commit
73709eda2b
|
@ -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);
|
||||
}
|
|
@ -616,22 +616,32 @@ 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();
|
||||
|
||||
// Start parsing the specified input file.
|
||||
|
||||
|
||||
delete PA;
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// ASTStreamer drivers
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
static void PrintASTs(Preprocessor &PP, unsigned MainFileID) {
|
||||
ASTStreamerTy *Streamer = ASTStreamer_Init(PP, MainFileID);
|
||||
|
||||
while (Decl *D = ASTStreamer_ReadTopLevelDecl(Streamer)) {
|
||||
std::cerr << "Read decl!\n";
|
||||
}
|
||||
|
||||
ASTStreamer_Terminate(Streamer);
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Main driver
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue