diff options
author | Mike Stump <mrs@apple.com> | 2008-06-19 19:28:49 +0000 |
---|---|---|
committer | Mike Stump <mrs@apple.com> | 2008-06-19 19:28:49 +0000 |
commit | a6f0177a864ac478eb9890319f2e8ea03695e91d (patch) | |
tree | 15e6925bd08fdb32947546b338aaaa8a81e7cc13 /lib/Parse/Parser.cpp | |
parent | b8e26e63d9dcc09351d75677721c6c9ff7045b54 (diff) |
Test commit to see if new account works.
I choose to remove extraneous whitespace at end of lines as a semantic
nop for the test.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@52503 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Parse/Parser.cpp')
-rw-r--r-- | lib/Parse/Parser.cpp | 120 |
1 files changed, 60 insertions, 60 deletions
diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp index 2296f57afc..84a1381443 100644 --- a/lib/Parse/Parser.cpp +++ b/lib/Parse/Parser.cpp @@ -41,10 +41,10 @@ void Parser::Diag(SourceLocation Loc, unsigned DiagID, /// should be the name of the unmatched LHS token. SourceLocation Parser::MatchRHSPunctuation(tok::TokenKind RHSTok, SourceLocation LHSLoc) { - + if (Tok.is(RHSTok)) return ConsumeAnyToken(); - + SourceLocation R = Tok.getLocation(); const char *LHSName = "unknown"; diag::kind DID = diag::err_parse_error; @@ -73,7 +73,7 @@ bool Parser::ExpectAndConsume(tok::TokenKind ExpectedTok, unsigned DiagID, ConsumeAnyToken(); return false; } - + Diag(Tok, DiagID, Msg); if (SkipToTok != tok::unknown) SkipUntil(SkipToTok); @@ -89,9 +89,9 @@ bool Parser::ExpectAndConsume(tok::TokenKind ExpectedTok, unsigned DiagID, /// token will ever occur, this skips to the next token, or to some likely /// good stopping point. If StopAtSemi is true, skipping will stop at a ';' /// character. -/// +/// /// If SkipUntil finds the specified token, it returns true, otherwise it -/// returns false. +/// returns false. bool Parser::SkipUntil(const tok::TokenKind *Toks, unsigned NumToks, bool StopAtSemi, bool DontConsume) { // We always want this function to skip at least one token if the first token @@ -109,12 +109,12 @@ bool Parser::SkipUntil(const tok::TokenKind *Toks, unsigned NumToks, return true; } } - + switch (Tok.getKind()) { case tok::eof: // Ran out of tokens. return false; - + case tok::l_paren: // Recursively skip properly-nested parens. ConsumeParen(); @@ -130,7 +130,7 @@ bool Parser::SkipUntil(const tok::TokenKind *Toks, unsigned NumToks, ConsumeBrace(); SkipUntil(tok::r_brace, false); break; - + // Okay, we found a ']' or '}' or ')', which we think should be balanced. // Since the user wasn't looking for this token (if they were, it would // already be handled), this isn't balanced. If there is a LHS token at a @@ -151,7 +151,7 @@ bool Parser::SkipUntil(const tok::TokenKind *Toks, unsigned NumToks, return false; // Matches something. ConsumeBrace(); break; - + case tok::string_literal: case tok::wide_string_literal: ConsumeStringToken(); @@ -166,7 +166,7 @@ bool Parser::SkipUntil(const tok::TokenKind *Toks, unsigned NumToks, break; } isFirstTokenSkipped = false; - } + } } //===----------------------------------------------------------------------===// @@ -192,10 +192,10 @@ void Parser::ExitScope() { // decls in it. if (!CurScope->decl_empty()) Actions.ActOnPopScope(Tok.getLocation(), CurScope); - + Scope *OldScope = CurScope; CurScope = OldScope->getParent(); - + if (NumCachedScopes == ScopeCacheSize) delete OldScope; else @@ -212,7 +212,7 @@ void Parser::ExitScope() { Parser::~Parser() { // If we still have scopes active, delete the scope tree. delete CurScope; - + // Free the scope cache. for (unsigned i = 0, e = NumCachedScopes; i != e; ++i) delete ScopeCache[i]; @@ -223,16 +223,16 @@ Parser::~Parser() { void Parser::Initialize() { // Prime the lexer look-ahead. ConsumeToken(); - + // Create the translation unit scope. Install it as the current scope. assert(CurScope == 0 && "A scope is already active?"); EnterScope(Scope::DeclScope); Actions.ActOnTranslationUnitScope(Tok.getLocation(), CurScope); - + if (Tok.is(tok::eof) && !getLang().CPlusPlus) // Empty source file is an extension in C Diag(Tok, diag::ext_empty_source_file); - + // Initialization for Objective-C context sensitive keywords recognition. // Referenced in Parser::ParseObjCTypeQualifierList. if (getLang().ObjC1) { @@ -248,11 +248,11 @@ void Parser::Initialize() { ObjCPropertyAttrs[objc_getter] = &PP.getIdentifierTable().get("getter"); ObjCPropertyAttrs[objc_setter] = &PP.getIdentifierTable().get("setter"); ObjCPropertyAttrs[objc_assign] = &PP.getIdentifierTable().get("assign"); - ObjCPropertyAttrs[objc_readwrite] = + ObjCPropertyAttrs[objc_readwrite] = &PP.getIdentifierTable().get("readwrite"); ObjCPropertyAttrs[objc_retain] = &PP.getIdentifierTable().get("retain"); ObjCPropertyAttrs[objc_copy] = &PP.getIdentifierTable().get("copy"); - ObjCPropertyAttrs[objc_nonatomic] = + ObjCPropertyAttrs[objc_nonatomic] = &PP.getIdentifierTable().get("nonatomic"); ObjCForCollectionInKW = &PP.getIdentifierTable().get("in"); } @@ -263,7 +263,7 @@ void Parser::Initialize() { bool Parser::ParseTopLevelDecl(DeclTy*& Result) { Result = 0; if (Tok.is(tok::eof)) return true; - + Result = ParseExternalDeclaration(); return false; } @@ -277,15 +277,15 @@ void Parser::Finalize() { /// ParseTranslationUnit: /// translation-unit: [C99 6.9] -/// external-declaration -/// translation-unit external-declaration +/// external-declaration +/// translation-unit external-declaration void Parser::ParseTranslationUnit() { Initialize(); - + DeclTy *Res; while (!ParseTopLevelDecl(Res)) /*parse them all*/; - + Finalize(); } @@ -322,7 +322,7 @@ Parser::DeclTy *Parser::ParseExternalDeclaration() { } case tok::kw_asm: { ExprResult Result = ParseSimpleAsm(); - + ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "top-level asm block"); @@ -359,7 +359,7 @@ Parser::DeclTy *Parser::ParseExternalDeclaration() { /// function-definition: [C99 6.9.1] /// decl-specs declarator declaration-list[opt] compound-statement /// [C90] function-definition: [C99 6.7.1] - implicit int result -/// [C90] decl-specs[opt] declarator declaration-list[opt] compound-statement +/// [C90] decl-specs[opt] declarator declaration-list[opt] compound-statement /// /// declaration: [C99 6.7] /// declaration-specifiers init-declarator-list[opt] ';' @@ -370,14 +370,14 @@ Parser::DeclTy *Parser::ParseDeclarationOrFunctionDefinition() { // Parse the common declaration-specifiers piece. DeclSpec DS; ParseDeclarationSpecifiers(DS); - + // C99 6.7.2.3p6: Handle "struct-or-union identifier;", "enum { X };" // declaration-specifiers init-declarator-list[opt] ';' if (Tok.is(tok::semi)) { ConsumeToken(); return Actions.ParsedFreeStandingDeclSpec(CurScope, DS); } - + // ObjC2 allows prefix attributes on class interfaces. if (getLang().ObjC2 && Tok.is(tok::at)) { SourceLocation AtLoc = ConsumeToken(); // the "@" @@ -389,9 +389,9 @@ Parser::DeclTy *Parser::ParseDeclarationOrFunctionDefinition() { const char *PrevSpec = 0; if (DS.SetTypeSpecType(DeclSpec::TST_unspecified, AtLoc, PrevSpec)) Diag(AtLoc, diag::err_invalid_decl_spec_combination, PrevSpec); - return ParseObjCAtInterfaceDeclaration(AtLoc, DS.getAttributes()); + return ParseObjCAtInterfaceDeclaration(AtLoc, DS.getAttributes()); } - + // If the declspec consisted only of 'extern' and we have a string // literal following it, this must be a C++ linkage specifier like // 'extern "C"'. @@ -424,10 +424,10 @@ Parser::DeclTy *Parser::ParseDeclarationOrFunctionDefinition() { isDeclarationSpecifier())) { // int X(f) int f; {} if (DS.getStorageClassSpec() == DeclSpec::SCS_typedef) { Diag(Tok, diag::err_function_declared_typedef); - + if (Tok.is(tok::l_brace)) { // This recovery skips the entire function body. It would be nice - // to simply call ParseFunctionDefintion() below, however Sema + // to simply call ParseFunctionDefintion() below, however Sema // assumes the declarator represents a function, not a typedef. ConsumeBrace(); SkipUntil(tok::r_brace, true); @@ -457,14 +457,14 @@ Parser::DeclTy *Parser::ParseDeclarationOrFunctionDefinition() { /// function-definition: [C99 6.9.1] /// decl-specs declarator declaration-list[opt] compound-statement /// [C90] function-definition: [C99 6.7.1] - implicit int result -/// [C90] decl-specs[opt] declarator declaration-list[opt] compound-statement +/// [C90] decl-specs[opt] declarator declaration-list[opt] compound-statement /// Parser::DeclTy *Parser::ParseFunctionDefinition(Declarator &D) { const DeclaratorChunk &FnTypeInfo = D.getTypeObject(0); assert(FnTypeInfo.Kind == DeclaratorChunk::Function && "This isn't a function declarator!"); const DeclaratorChunk::FunctionTypeInfo &FTI = FnTypeInfo.Fun; - + // If this is C90 and the declspecs were completely missing, fudge in an // implicit int. We do this here because this is the only place where // declaration-specifiers are completely optional in the grammar. @@ -473,7 +473,7 @@ Parser::DeclTy *Parser::ParseFunctionDefinition(Declarator &D) { D.getDeclSpec().SetTypeSpecType(DeclSpec::TST_int, D.getIdentifierLoc(), PrevSpec); } - + // If this declaration was formed with a K&R-style identifier list for the // arguments, parse declarations for all of the args next. // int foo(a,b) int a; float b; {} @@ -486,22 +486,22 @@ Parser::DeclTy *Parser::ParseFunctionDefinition(Declarator &D) { // Skip over garbage, until we get to '{'. Don't eat the '{'. SkipUntil(tok::l_brace, true, true); - + // If we didn't find the '{', bail out. if (Tok.isNot(tok::l_brace)) return 0; } - + SourceLocation BraceLoc = Tok.getLocation(); - + // Enter a scope for the function body. EnterScope(Scope::FnScope|Scope::DeclScope); - + // Tell the actions module that we have entered a function definition with the // specified Declarator for the function. DeclTy *Res = Actions.ActOnStartOfFunctionDef(CurScope, D); - - return ParseFunctionStatementBody(Res, BraceLoc, BraceLoc); + + return ParseFunctionStatementBody(Res, BraceLoc, BraceLoc); } /// ParseKNRParamDeclarations - Parse 'declaration-list[opt]' which provides @@ -517,11 +517,11 @@ void Parser::ParseKNRParamDeclarations(Declarator &D) { // Read all the argument declarations. while (isDeclarationSpecifier()) { SourceLocation DSStart = Tok.getLocation(); - + // Parse the common declaration-specifiers piece. DeclSpec DS; ParseDeclarationSpecifiers(DS); - + // C99 6.9.1p6: 'each declaration in the declaration list shall have at // least one declarator'. // NOTE: GCC just makes this an ext-warn. It's not clear what it does with @@ -532,7 +532,7 @@ void Parser::ParseKNRParamDeclarations(Declarator &D) { ConsumeToken(); continue; } - + // C99 6.9.1p6: Declarations shall contain no storage-class specifiers other // than register. if (DS.getStorageClassSpec() != DeclSpec::SCS_unspecified && @@ -546,7 +546,7 @@ void Parser::ParseKNRParamDeclarations(Declarator &D) { diag::err_invalid_storage_class_in_func_decl); DS.ClearStorageClassSpecs(); } - + // Parse the first declarator attached to this declspec. Declarator ParmDeclarator(DS, Declarator::KNRTypeListContext); ParseDeclarator(ParmDeclarator); @@ -558,12 +558,12 @@ void Parser::ParseKNRParamDeclarations(Declarator &D) { if (Tok.is(tok::kw___attribute)) // FIXME: attach attributes too. AttrList = ParseAttributes(); - + // Ask the actions module to compute the type for this declarator. - Action::DeclTy *Param = + Action::DeclTy *Param = Actions.ActOnParamDeclarator(CurScope, ParmDeclarator); - if (Param && + if (Param && // A missing identifier has already been diagnosed. ParmDeclarator.getIdentifier()) { @@ -577,7 +577,7 @@ void Parser::ParseKNRParamDeclarations(Declarator &D) { ParmDeclarator.getIdentifier()->getName()); break; } - + if (FTI.ArgInfo[i].Ident == ParmDeclarator.getIdentifier()) { // Reject redefinitions of parameters. if (FTI.ArgInfo[i].Param) { @@ -596,15 +596,15 @@ void Parser::ParseKNRParamDeclarations(Declarator &D) { // an error, bail out. if (Tok.isNot(tok::comma)) break; - + // Consume the comma. ConsumeToken(); - + // Parse the next declarator. ParmDeclarator.clear(); ParseDeclarator(ParmDeclarator); } - + if (Tok.is(tok::semi)) { ConsumeToken(); } else { @@ -615,7 +615,7 @@ void Parser::ParseKNRParamDeclarations(Declarator &D) { ConsumeToken(); } } - + // Leave prototype scope. ExitScope(); @@ -634,12 +634,12 @@ Parser::ExprResult Parser::ParseAsmStringLiteral() { Diag(Tok, diag::err_expected_string_literal); return true; } - + ExprResult Res = ParseStringLiteralExpression(); if (Res.isInvalid) return true; - + // TODO: Diagnose: wide string literal in 'asm' - + return Res; } @@ -651,18 +651,18 @@ Parser::ExprResult Parser::ParseAsmStringLiteral() { Parser::ExprResult Parser::ParseSimpleAsm() { assert(Tok.is(tok::kw_asm) && "Not an asm!"); SourceLocation Loc = ConsumeToken(); - + if (Tok.isNot(tok::l_paren)) { Diag(Tok, diag::err_expected_lparen_after, "asm"); return true; } - + ConsumeParen(); - + ExprResult Result = ParseAsmStringLiteral(); - + MatchRHSPunctuation(tok::r_paren, Loc); - + return Result; } |