forked from OSchip/llvm-project
parent
73709eda2b
commit
38ba3363ef
|
@ -30,13 +30,21 @@ namespace {
|
|||
: P(PP, Builder) {
|
||||
PP.EnterSourceFile(MainFileID, 0, true);
|
||||
|
||||
// Parsing the specified input file.
|
||||
P.ParseTranslationUnit();
|
||||
// Initialize the parser.
|
||||
P.Initialize();
|
||||
}
|
||||
|
||||
/// ReadTopLevelDecl - Parse and return the next top-level declaration.
|
||||
Decl *ReadTopLevelDecl() {
|
||||
return 0;
|
||||
Parser::DeclTy *Result;
|
||||
if (P.ParseTopLevelDecl(Result))
|
||||
return 0;
|
||||
Result = (Decl*)1; // FIXME!
|
||||
return (Decl*)Result;
|
||||
}
|
||||
|
||||
~ASTStreamer() {
|
||||
P.Finalize();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -195,18 +195,16 @@ void Parser::ExitScope() {
|
|||
// C99 6.9: External Definitions.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/// ParseTranslationUnit:
|
||||
/// translation-unit: [C99 6.9]
|
||||
/// external-declaration
|
||||
/// translation-unit external-declaration
|
||||
void Parser::ParseTranslationUnit() {
|
||||
/// Initialize - Warm up the parser.
|
||||
///
|
||||
void Parser::Initialize() {
|
||||
// Prime the lexer look-ahead.
|
||||
ConsumeToken();
|
||||
|
||||
// Create the global scope, install it as the current scope.
|
||||
assert(CurScope == 0 && "A scope is already active?");
|
||||
EnterScope();
|
||||
|
||||
|
||||
|
||||
// Install builtin types.
|
||||
// TODO: Move this someplace more useful.
|
||||
|
@ -217,23 +215,47 @@ void Parser::ParseTranslationUnit() {
|
|||
|
||||
// TODO: add a 'TST_builtin' type?
|
||||
DS.TypeSpecType = DeclSpec::TST_typedef;
|
||||
|
||||
|
||||
Declarator D(DS, Declarator::FileContext);
|
||||
D.SetIdentifier(PP.getIdentifierInfo("__builtin_va_list"),SourceLocation());
|
||||
Actions.ParseDeclarator(SourceLocation(), CurScope, D, 0);
|
||||
}
|
||||
|
||||
|
||||
if (Tok.getKind() == tok::eof) // Empty source file is an extension.
|
||||
Diag(diag::ext_empty_source_file);
|
||||
}
|
||||
|
||||
/// ParseTopLevelDecl - Parse one top-level declaration, return whatever the
|
||||
/// action tells us to. This returns true if the EOF was encountered.
|
||||
bool Parser::ParseTopLevelDecl(DeclTy*& Result) {
|
||||
Result = 0;
|
||||
if (Tok.getKind() == tok::eof) return true;
|
||||
|
||||
while (Tok.getKind() != tok::eof)
|
||||
ParseExternalDeclaration();
|
||||
|
||||
ParseExternalDeclaration();
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Finalize - Shut down the parser.
|
||||
///
|
||||
void Parser::Finalize() {
|
||||
ExitScope();
|
||||
assert(CurScope == 0 && "Scope imbalance!");
|
||||
}
|
||||
|
||||
/// ParseTranslationUnit:
|
||||
/// translation-unit: [C99 6.9]
|
||||
/// external-declaration
|
||||
/// translation-unit external-declaration
|
||||
void Parser::ParseTranslationUnit() {
|
||||
Initialize();
|
||||
|
||||
DeclTy *Res;
|
||||
while (!ParseTopLevelDecl(Res))
|
||||
/*parse them all*/;
|
||||
|
||||
Finalize();
|
||||
}
|
||||
|
||||
/// ParseExternalDeclaration:
|
||||
/// external-declaration: [C99 6.9]
|
||||
/// function-definition [TODO]
|
||||
|
|
|
@ -30,13 +30,21 @@ namespace {
|
|||
: P(PP, Builder) {
|
||||
PP.EnterSourceFile(MainFileID, 0, true);
|
||||
|
||||
// Parsing the specified input file.
|
||||
P.ParseTranslationUnit();
|
||||
// Initialize the parser.
|
||||
P.Initialize();
|
||||
}
|
||||
|
||||
/// ReadTopLevelDecl - Parse and return the next top-level declaration.
|
||||
Decl *ReadTopLevelDecl() {
|
||||
return 0;
|
||||
Parser::DeclTy *Result;
|
||||
if (P.ParseTopLevelDecl(Result))
|
||||
return 0;
|
||||
Result = (Decl*)1; // FIXME!
|
||||
return (Decl*)Result;
|
||||
}
|
||||
|
||||
~ASTStreamer() {
|
||||
P.Finalize();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -46,16 +46,25 @@ public:
|
|||
// Type forwarding. All of these are statically 'void*', but they may all be
|
||||
// different actual classes based on the actions in place.
|
||||
typedef Action::ExprTy ExprTy;
|
||||
typedef Action::DeclTy DeclTy;
|
||||
|
||||
// Parsing methods.
|
||||
|
||||
/// ParseTranslationUnit - All in one method that initializes parses, and
|
||||
/// shuts down the parser.
|
||||
void ParseTranslationUnit();
|
||||
|
||||
struct ExprResult {
|
||||
ExprTy *Val;
|
||||
bool isInvalid;
|
||||
|
||||
ExprResult(bool Invalid = false) : Val(0), isInvalid(Invalid) {}
|
||||
};
|
||||
/// Initialize - Warm up the parser.
|
||||
///
|
||||
void Initialize();
|
||||
|
||||
/// ParseTopLevelDecl - Parse one top-level declaration, return whatever the
|
||||
/// action tells us to. This returns true if the EOF was encountered.
|
||||
bool ParseTopLevelDecl(DeclTy*& Result);
|
||||
|
||||
/// Finalize - Shut down the parser.
|
||||
///
|
||||
void Finalize();
|
||||
|
||||
private:
|
||||
//===--------------------------------------------------------------------===//
|
||||
|
@ -209,6 +218,13 @@ private:
|
|||
|
||||
//===--------------------------------------------------------------------===//
|
||||
// C99 6.5: Expressions.
|
||||
|
||||
struct ExprResult {
|
||||
ExprTy *Val;
|
||||
bool isInvalid;
|
||||
|
||||
ExprResult(bool Invalid = false) : Val(0), isInvalid(Invalid) {}
|
||||
};
|
||||
|
||||
ExprResult ParseExpression();
|
||||
ExprResult ParseConstantExpression();
|
||||
|
|
Loading…
Reference in New Issue