Chris Lattner | eb8a28f | 2006-08-10 18:43:39 +0000 | [diff] [blame] | 1 | //===--- Parser.cpp - C Language Family Parser ----------------------------===// |
Chris Lattner | 0bb5f83 | 2006-07-31 01:59:18 +0000 | [diff] [blame] | 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 Parser interfaces. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/Parse/Parser.h" |
Chris Lattner | 288e86ff1 | 2006-11-11 23:03:42 +0000 | [diff] [blame] | 15 | #include "clang/Parse/DeclSpec.h" |
Chris Lattner | 971c6b6 | 2006-08-05 22:46:42 +0000 | [diff] [blame] | 16 | #include "clang/Parse/Scope.h" |
Chris Lattner | 0bb5f83 | 2006-07-31 01:59:18 +0000 | [diff] [blame] | 17 | using namespace clang; |
| 18 | |
Chris Lattner | 697e5d6 | 2006-11-09 06:32:27 +0000 | [diff] [blame] | 19 | Parser::Parser(Preprocessor &pp, Action &actions) |
| 20 | : PP(pp), Actions(actions), Diags(PP.getDiagnostics()) { |
Chris Lattner | 8c20487 | 2006-10-14 05:19:21 +0000 | [diff] [blame] | 21 | Tok.setKind(tok::eof); |
Chris Lattner | e4e3859 | 2006-08-14 00:15:05 +0000 | [diff] [blame] | 22 | CurScope = 0; |
Chris Lattner | 03928c7 | 2007-07-15 00:04:39 +0000 | [diff] [blame] | 23 | NumCachedScopes = 0; |
Chris Lattner | eec40f9 | 2006-08-06 21:55:29 +0000 | [diff] [blame] | 24 | ParenCount = BracketCount = BraceCount = 0; |
Chris Lattner | 971c6b6 | 2006-08-05 22:46:42 +0000 | [diff] [blame] | 25 | } |
| 26 | |
Chris Lattner | 685ed1e | 2006-08-14 00:22:04 +0000 | [diff] [blame] | 27 | /// Out-of-line virtual destructor to provide home for Action class. |
| 28 | Action::~Action() {} |
Chris Lattner | e4e3859 | 2006-08-14 00:15:05 +0000 | [diff] [blame] | 29 | |
Chris Lattner | 0bb5f83 | 2006-07-31 01:59:18 +0000 | [diff] [blame] | 30 | |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 31 | void Parser::Diag(SourceLocation Loc, unsigned DiagID, |
Chris Lattner | 0bb5f83 | 2006-07-31 01:59:18 +0000 | [diff] [blame] | 32 | const std::string &Msg) { |
Chris Lattner | 36982e4 | 2007-05-16 17:49:37 +0000 | [diff] [blame] | 33 | Diags.Report(Loc, DiagID, &Msg, 1); |
Chris Lattner | 0bb5f83 | 2006-07-31 01:59:18 +0000 | [diff] [blame] | 34 | } |
| 35 | |
Chris Lattner | 4564bc1 | 2006-08-10 23:14:52 +0000 | [diff] [blame] | 36 | /// MatchRHSPunctuation - For punctuation with a LHS and RHS (e.g. '['/']'), |
| 37 | /// this helper function matches and consumes the specified RHS token if |
| 38 | /// present. If not present, it emits the specified diagnostic indicating |
| 39 | /// that the parser failed to match the RHS of the token at LHSLoc. LHSName |
| 40 | /// should be the name of the unmatched LHS token. |
Chris Lattner | 71e23ce | 2006-11-04 20:18:38 +0000 | [diff] [blame] | 41 | SourceLocation Parser::MatchRHSPunctuation(tok::TokenKind RHSTok, |
| 42 | SourceLocation LHSLoc) { |
Chris Lattner | 4564bc1 | 2006-08-10 23:14:52 +0000 | [diff] [blame] | 43 | |
Chris Lattner | 71e23ce | 2006-11-04 20:18:38 +0000 | [diff] [blame] | 44 | if (Tok.getKind() == RHSTok) |
| 45 | return ConsumeAnyToken(); |
| 46 | |
| 47 | SourceLocation R = Tok.getLocation(); |
| 48 | const char *LHSName = "unknown"; |
| 49 | diag::kind DID = diag::err_parse_error; |
| 50 | switch (RHSTok) { |
| 51 | default: break; |
| 52 | case tok::r_paren : LHSName = "("; DID = diag::err_expected_rparen; break; |
| 53 | case tok::r_brace : LHSName = "{"; DID = diag::err_expected_rbrace; break; |
| 54 | case tok::r_square: LHSName = "["; DID = diag::err_expected_rsquare; break; |
Chris Lattner | 2937565 | 2006-12-04 18:06:35 +0000 | [diff] [blame] | 55 | case tok::greater: LHSName = "<"; DID = diag::err_expected_greater; break; |
Chris Lattner | 4564bc1 | 2006-08-10 23:14:52 +0000 | [diff] [blame] | 56 | } |
Chris Lattner | 71e23ce | 2006-11-04 20:18:38 +0000 | [diff] [blame] | 57 | Diag(Tok, DID); |
| 58 | Diag(LHSLoc, diag::err_matching, LHSName); |
| 59 | SkipUntil(RHSTok); |
| 60 | return R; |
Chris Lattner | 4564bc1 | 2006-08-10 23:14:52 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Chris Lattner | dbb2a46 | 2006-08-12 19:26:13 +0000 | [diff] [blame] | 63 | /// ExpectAndConsume - The parser expects that 'ExpectedTok' is next in the |
| 64 | /// input. If so, it is consumed and false is returned. |
| 65 | /// |
| 66 | /// If the input is malformed, this emits the specified diagnostic. Next, if |
| 67 | /// SkipToTok is specified, it calls SkipUntil(SkipToTok). Finally, true is |
| 68 | /// returned. |
| 69 | bool Parser::ExpectAndConsume(tok::TokenKind ExpectedTok, unsigned DiagID, |
Chris Lattner | 6d7e634 | 2006-08-15 03:41:14 +0000 | [diff] [blame] | 70 | const char *Msg, tok::TokenKind SkipToTok) { |
Chris Lattner | dbb2a46 | 2006-08-12 19:26:13 +0000 | [diff] [blame] | 71 | if (Tok.getKind() == ExpectedTok) { |
Chris Lattner | 15a00da | 2006-08-15 04:10:31 +0000 | [diff] [blame] | 72 | ConsumeAnyToken(); |
Chris Lattner | dbb2a46 | 2006-08-12 19:26:13 +0000 | [diff] [blame] | 73 | return false; |
| 74 | } |
| 75 | |
Chris Lattner | 6d7e634 | 2006-08-15 03:41:14 +0000 | [diff] [blame] | 76 | Diag(Tok, DiagID, Msg); |
Chris Lattner | dbb2a46 | 2006-08-12 19:26:13 +0000 | [diff] [blame] | 77 | if (SkipToTok != tok::unknown) |
| 78 | SkipUntil(SkipToTok); |
| 79 | return true; |
| 80 | } |
| 81 | |
Chris Lattner | 70f32b7 | 2006-07-31 05:09:04 +0000 | [diff] [blame] | 82 | //===----------------------------------------------------------------------===// |
Chris Lattner | eec40f9 | 2006-08-06 21:55:29 +0000 | [diff] [blame] | 83 | // Error recovery. |
| 84 | //===----------------------------------------------------------------------===// |
| 85 | |
| 86 | /// SkipUntil - Read tokens until we get to the specified token, then consume |
Chris Lattner | 01e4b24 | 2007-07-24 17:03:04 +0000 | [diff] [blame] | 87 | /// it (unless DontConsume is true). Because we cannot guarantee that the |
Chris Lattner | eec40f9 | 2006-08-06 21:55:29 +0000 | [diff] [blame] | 88 | /// token will ever occur, this skips to the next token, or to some likely |
| 89 | /// good stopping point. If StopAtSemi is true, skipping will stop at a ';' |
| 90 | /// character. |
| 91 | /// |
| 92 | /// If SkipUntil finds the specified token, it returns true, otherwise it |
| 93 | /// returns false. |
Chris Lattner | 83b94e0 | 2007-04-27 19:12:15 +0000 | [diff] [blame] | 94 | bool Parser::SkipUntil(const tok::TokenKind *Toks, unsigned NumToks, |
| 95 | bool StopAtSemi, bool DontConsume) { |
Chris Lattner | 5bd57e0 | 2006-08-11 06:40:25 +0000 | [diff] [blame] | 96 | // We always want this function to skip at least one token if the first token |
| 97 | // isn't T and if not at EOF. |
| 98 | bool isFirstTokenSkipped = true; |
Chris Lattner | eec40f9 | 2006-08-06 21:55:29 +0000 | [diff] [blame] | 99 | while (1) { |
Chris Lattner | 83b94e0 | 2007-04-27 19:12:15 +0000 | [diff] [blame] | 100 | // If we found one of the tokens, stop and return true. |
| 101 | for (unsigned i = 0; i != NumToks; ++i) { |
| 102 | if (Tok.getKind() == Toks[i]) { |
| 103 | if (DontConsume) { |
| 104 | // Noop, don't consume the token. |
| 105 | } else { |
| 106 | ConsumeAnyToken(); |
| 107 | } |
| 108 | return true; |
Chris Lattner | eec40f9 | 2006-08-06 21:55:29 +0000 | [diff] [blame] | 109 | } |
Chris Lattner | eec40f9 | 2006-08-06 21:55:29 +0000 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | switch (Tok.getKind()) { |
| 113 | case tok::eof: |
| 114 | // Ran out of tokens. |
| 115 | return false; |
| 116 | |
| 117 | case tok::l_paren: |
| 118 | // Recursively skip properly-nested parens. |
| 119 | ConsumeParen(); |
Chris Lattner | 5bd57e0 | 2006-08-11 06:40:25 +0000 | [diff] [blame] | 120 | SkipUntil(tok::r_paren, false); |
Chris Lattner | eec40f9 | 2006-08-06 21:55:29 +0000 | [diff] [blame] | 121 | break; |
| 122 | case tok::l_square: |
| 123 | // Recursively skip properly-nested square brackets. |
| 124 | ConsumeBracket(); |
Chris Lattner | 5bd57e0 | 2006-08-11 06:40:25 +0000 | [diff] [blame] | 125 | SkipUntil(tok::r_square, false); |
Chris Lattner | eec40f9 | 2006-08-06 21:55:29 +0000 | [diff] [blame] | 126 | break; |
| 127 | case tok::l_brace: |
| 128 | // Recursively skip properly-nested braces. |
| 129 | ConsumeBrace(); |
Chris Lattner | 5bd57e0 | 2006-08-11 06:40:25 +0000 | [diff] [blame] | 130 | SkipUntil(tok::r_brace, false); |
Chris Lattner | eec40f9 | 2006-08-06 21:55:29 +0000 | [diff] [blame] | 131 | break; |
| 132 | |
| 133 | // Okay, we found a ']' or '}' or ')', which we think should be balanced. |
| 134 | // Since the user wasn't looking for this token (if they were, it would |
| 135 | // already be handled), this isn't balanced. If there is a LHS token at a |
| 136 | // higher level, we will assume that this matches the unbalanced token |
| 137 | // and return it. Otherwise, this is a spurious RHS token, which we skip. |
| 138 | case tok::r_paren: |
Chris Lattner | 5bd57e0 | 2006-08-11 06:40:25 +0000 | [diff] [blame] | 139 | if (ParenCount && !isFirstTokenSkipped) |
| 140 | return false; // Matches something. |
Chris Lattner | eec40f9 | 2006-08-06 21:55:29 +0000 | [diff] [blame] | 141 | ConsumeParen(); |
| 142 | break; |
| 143 | case tok::r_square: |
Chris Lattner | 5bd57e0 | 2006-08-11 06:40:25 +0000 | [diff] [blame] | 144 | if (BracketCount && !isFirstTokenSkipped) |
| 145 | return false; // Matches something. |
Chris Lattner | eec40f9 | 2006-08-06 21:55:29 +0000 | [diff] [blame] | 146 | ConsumeBracket(); |
| 147 | break; |
| 148 | case tok::r_brace: |
Chris Lattner | 5bd57e0 | 2006-08-11 06:40:25 +0000 | [diff] [blame] | 149 | if (BraceCount && !isFirstTokenSkipped) |
| 150 | return false; // Matches something. |
Chris Lattner | eec40f9 | 2006-08-06 21:55:29 +0000 | [diff] [blame] | 151 | ConsumeBrace(); |
| 152 | break; |
| 153 | |
| 154 | case tok::string_literal: |
Chris Lattner | d3e9895 | 2006-10-06 05:22:26 +0000 | [diff] [blame] | 155 | case tok::wide_string_literal: |
Chris Lattner | eec40f9 | 2006-08-06 21:55:29 +0000 | [diff] [blame] | 156 | ConsumeStringToken(); |
| 157 | break; |
| 158 | case tok::semi: |
| 159 | if (StopAtSemi) |
| 160 | return false; |
| 161 | // FALL THROUGH. |
| 162 | default: |
| 163 | // Skip this token. |
| 164 | ConsumeToken(); |
| 165 | break; |
| 166 | } |
Chris Lattner | 5bd57e0 | 2006-08-11 06:40:25 +0000 | [diff] [blame] | 167 | isFirstTokenSkipped = false; |
Chris Lattner | eec40f9 | 2006-08-06 21:55:29 +0000 | [diff] [blame] | 168 | } |
| 169 | } |
| 170 | |
| 171 | //===----------------------------------------------------------------------===// |
Chris Lattner | e4e3859 | 2006-08-14 00:15:05 +0000 | [diff] [blame] | 172 | // Scope manipulation |
| 173 | //===----------------------------------------------------------------------===// |
| 174 | |
| 175 | /// EnterScope - Start a new scope. |
Chris Lattner | 33ad2ca | 2006-11-05 23:47:55 +0000 | [diff] [blame] | 176 | void Parser::EnterScope(unsigned ScopeFlags) { |
Chris Lattner | 03928c7 | 2007-07-15 00:04:39 +0000 | [diff] [blame] | 177 | if (NumCachedScopes) { |
| 178 | Scope *N = ScopeCache[--NumCachedScopes]; |
Chris Lattner | b6a0e17 | 2006-11-06 00:22:42 +0000 | [diff] [blame] | 179 | N->Init(CurScope, ScopeFlags); |
| 180 | CurScope = N; |
| 181 | } else { |
| 182 | CurScope = new Scope(CurScope, ScopeFlags); |
| 183 | } |
Chris Lattner | e4e3859 | 2006-08-14 00:15:05 +0000 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | /// ExitScope - Pop a scope off the scope stack. |
| 187 | void Parser::ExitScope() { |
| 188 | assert(CurScope && "Scope imbalance!"); |
| 189 | |
| 190 | // Inform the actions module that this scope is going away. |
| 191 | Actions.PopScope(Tok.getLocation(), CurScope); |
| 192 | |
Chris Lattner | 03928c7 | 2007-07-15 00:04:39 +0000 | [diff] [blame] | 193 | Scope *OldScope = CurScope; |
| 194 | CurScope = OldScope->getParent(); |
Chris Lattner | b6a0e17 | 2006-11-06 00:22:42 +0000 | [diff] [blame] | 195 | |
Chris Lattner | 03928c7 | 2007-07-15 00:04:39 +0000 | [diff] [blame] | 196 | if (NumCachedScopes == ScopeCacheSize) |
| 197 | delete OldScope; |
Chris Lattner | b6a0e17 | 2006-11-06 00:22:42 +0000 | [diff] [blame] | 198 | else |
Chris Lattner | 03928c7 | 2007-07-15 00:04:39 +0000 | [diff] [blame] | 199 | ScopeCache[NumCachedScopes++] = OldScope; |
Chris Lattner | e4e3859 | 2006-08-14 00:15:05 +0000 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | //===----------------------------------------------------------------------===// |
Chris Lattner | 70f32b7 | 2006-07-31 05:09:04 +0000 | [diff] [blame] | 206 | // C99 6.9: External Definitions. |
| 207 | //===----------------------------------------------------------------------===// |
Chris Lattner | 0bb5f83 | 2006-07-31 01:59:18 +0000 | [diff] [blame] | 208 | |
Chris Lattner | b6a0e17 | 2006-11-06 00:22:42 +0000 | [diff] [blame] | 209 | Parser::~Parser() { |
| 210 | // If we still have scopes active, delete the scope tree. |
| 211 | delete CurScope; |
| 212 | |
| 213 | // Free the scope cache. |
Chris Lattner | 03928c7 | 2007-07-15 00:04:39 +0000 | [diff] [blame] | 214 | for (unsigned i = 0, e = NumCachedScopes; i != e; ++i) |
| 215 | delete ScopeCache[i]; |
Chris Lattner | b6a0e17 | 2006-11-06 00:22:42 +0000 | [diff] [blame] | 216 | } |
| 217 | |
Chris Lattner | 38ba336 | 2006-08-17 07:04:37 +0000 | [diff] [blame] | 218 | /// Initialize - Warm up the parser. |
| 219 | /// |
| 220 | void Parser::Initialize() { |
Chris Lattner | e4e3859 | 2006-08-14 00:15:05 +0000 | [diff] [blame] | 221 | // Prime the lexer look-ahead. |
| 222 | ConsumeToken(); |
| 223 | |
| 224 | // Create the global scope, install it as the current scope. |
| 225 | assert(CurScope == 0 && "A scope is already active?"); |
Chris Lattner | 33ad2ca | 2006-11-05 23:47:55 +0000 | [diff] [blame] | 226 | EnterScope(0); |
Chris Lattner | 38ba336 | 2006-08-17 07:04:37 +0000 | [diff] [blame] | 227 | |
Chris Lattner | 6d7e634 | 2006-08-15 03:41:14 +0000 | [diff] [blame] | 228 | |
| 229 | // Install builtin types. |
| 230 | // TODO: Move this someplace more useful. |
| 231 | { |
Chris Lattner | 353f574 | 2006-11-28 04:50:12 +0000 | [diff] [blame] | 232 | const char *Dummy; |
| 233 | |
Chris Lattner | 6d7e634 | 2006-08-15 03:41:14 +0000 | [diff] [blame] | 234 | //__builtin_va_list |
| 235 | DeclSpec DS; |
Chris Lattner | 4d8f873 | 2006-11-28 05:05:08 +0000 | [diff] [blame] | 236 | bool Error = DS.SetStorageClassSpec(DeclSpec::SCS_typedef, SourceLocation(), |
| 237 | Dummy); |
Chris Lattner | 6d7e634 | 2006-08-15 03:41:14 +0000 | [diff] [blame] | 238 | |
| 239 | // TODO: add a 'TST_builtin' type? |
Chris Lattner | b20e894 | 2006-11-28 05:30:29 +0000 | [diff] [blame] | 240 | Error |= DS.SetTypeSpecType(DeclSpec::TST_int, SourceLocation(), Dummy); |
Chris Lattner | 353f574 | 2006-11-28 04:50:12 +0000 | [diff] [blame] | 241 | assert(!Error && "Error setting up __builtin_va_list!"); |
Chris Lattner | 38ba336 | 2006-08-17 07:04:37 +0000 | [diff] [blame] | 242 | |
Chris Lattner | 6d7e634 | 2006-08-15 03:41:14 +0000 | [diff] [blame] | 243 | Declarator D(DS, Declarator::FileContext); |
| 244 | D.SetIdentifier(PP.getIdentifierInfo("__builtin_va_list"),SourceLocation()); |
Chris Lattner | 2dacc3f | 2006-10-16 00:33:54 +0000 | [diff] [blame] | 245 | Actions.ParseDeclarator(CurScope, D, 0, 0); |
Chris Lattner | 6d7e634 | 2006-08-15 03:41:14 +0000 | [diff] [blame] | 246 | } |
| 247 | |
Chris Lattner | 0bb5f83 | 2006-07-31 01:59:18 +0000 | [diff] [blame] | 248 | if (Tok.getKind() == tok::eof) // Empty source file is an extension. |
Chris Lattner | bd63892 | 2006-11-10 05:19:25 +0000 | [diff] [blame] | 249 | Diag(Tok, diag::ext_empty_source_file); |
Chris Lattner | 38ba336 | 2006-08-17 07:04:37 +0000 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | /// ParseTopLevelDecl - Parse one top-level declaration, return whatever the |
| 253 | /// action tells us to. This returns true if the EOF was encountered. |
| 254 | bool Parser::ParseTopLevelDecl(DeclTy*& Result) { |
| 255 | Result = 0; |
| 256 | if (Tok.getKind() == tok::eof) return true; |
Chris Lattner | 0bb5f83 | 2006-07-31 01:59:18 +0000 | [diff] [blame] | 257 | |
Chris Lattner | 2dacc3f | 2006-10-16 00:33:54 +0000 | [diff] [blame] | 258 | Result = ParseExternalDeclaration(); |
Chris Lattner | 38ba336 | 2006-08-17 07:04:37 +0000 | [diff] [blame] | 259 | return false; |
| 260 | } |
| 261 | |
| 262 | /// Finalize - Shut down the parser. |
| 263 | /// |
| 264 | void Parser::Finalize() { |
Chris Lattner | e4e3859 | 2006-08-14 00:15:05 +0000 | [diff] [blame] | 265 | ExitScope(); |
| 266 | assert(CurScope == 0 && "Scope imbalance!"); |
Chris Lattner | 0bb5f83 | 2006-07-31 01:59:18 +0000 | [diff] [blame] | 267 | } |
| 268 | |
Chris Lattner | 38ba336 | 2006-08-17 07:04:37 +0000 | [diff] [blame] | 269 | /// ParseTranslationUnit: |
| 270 | /// translation-unit: [C99 6.9] |
| 271 | /// external-declaration |
| 272 | /// translation-unit external-declaration |
| 273 | void Parser::ParseTranslationUnit() { |
| 274 | Initialize(); |
| 275 | |
| 276 | DeclTy *Res; |
| 277 | while (!ParseTopLevelDecl(Res)) |
| 278 | /*parse them all*/; |
| 279 | |
| 280 | Finalize(); |
| 281 | } |
| 282 | |
Chris Lattner | 0bb5f83 | 2006-07-31 01:59:18 +0000 | [diff] [blame] | 283 | /// ParseExternalDeclaration: |
Chris Lattner | 70f32b7 | 2006-07-31 05:09:04 +0000 | [diff] [blame] | 284 | /// external-declaration: [C99 6.9] |
Chris Lattner | cccc311 | 2007-08-10 20:57:02 +0000 | [diff] [blame] | 285 | /// function-definition |
| 286 | /// declaration |
Chris Lattner | 0bb5f83 | 2006-07-31 01:59:18 +0000 | [diff] [blame] | 287 | /// [EXT] ';' |
Chris Lattner | 6d7e634 | 2006-08-15 03:41:14 +0000 | [diff] [blame] | 288 | /// [GNU] asm-definition |
Chris Lattner | cccc311 | 2007-08-10 20:57:02 +0000 | [diff] [blame] | 289 | /// [GNU] __extension__ external-declaration |
Chris Lattner | 40f16b5 | 2006-11-05 02:05:37 +0000 | [diff] [blame] | 290 | /// [OBJC] objc-class-definition |
| 291 | /// [OBJC] objc-class-declaration |
| 292 | /// [OBJC] objc-alias-declaration |
| 293 | /// [OBJC] objc-protocol-definition |
| 294 | /// [OBJC] objc-method-definition |
| 295 | /// [OBJC] @end |
Chris Lattner | 0bb5f83 | 2006-07-31 01:59:18 +0000 | [diff] [blame] | 296 | /// |
Chris Lattner | 6d7e634 | 2006-08-15 03:41:14 +0000 | [diff] [blame] | 297 | /// [GNU] asm-definition: |
| 298 | /// simple-asm-expr ';' |
| 299 | /// |
Chris Lattner | 2dacc3f | 2006-10-16 00:33:54 +0000 | [diff] [blame] | 300 | Parser::DeclTy *Parser::ParseExternalDeclaration() { |
Chris Lattner | 0bb5f83 | 2006-07-31 01:59:18 +0000 | [diff] [blame] | 301 | switch (Tok.getKind()) { |
| 302 | case tok::semi: |
Chris Lattner | bd63892 | 2006-11-10 05:19:25 +0000 | [diff] [blame] | 303 | Diag(Tok, diag::ext_top_level_semi); |
Chris Lattner | 0bb5f83 | 2006-07-31 01:59:18 +0000 | [diff] [blame] | 304 | ConsumeToken(); |
Chris Lattner | 2dacc3f | 2006-10-16 00:33:54 +0000 | [diff] [blame] | 305 | // TODO: Invoke action for top-level semicolon. |
| 306 | return 0; |
Chris Lattner | cccc311 | 2007-08-10 20:57:02 +0000 | [diff] [blame] | 307 | case tok::kw___extension__: { |
| 308 | ConsumeToken(); |
| 309 | // FIXME: Disable extension warnings. |
| 310 | DeclTy *RV = ParseExternalDeclaration(); |
| 311 | // FIXME: Restore extension warnings. |
| 312 | return RV; |
| 313 | } |
Chris Lattner | 6d7e634 | 2006-08-15 03:41:14 +0000 | [diff] [blame] | 314 | case tok::kw_asm: |
| 315 | ParseSimpleAsm(); |
| 316 | ExpectAndConsume(tok::semi, diag::err_expected_semi_after, |
| 317 | "top-level asm block"); |
Chris Lattner | 2dacc3f | 2006-10-16 00:33:54 +0000 | [diff] [blame] | 318 | // TODO: Invoke action for top-level asm. |
| 319 | return 0; |
Steve Naroff | b419d3a | 2006-10-27 23:18:49 +0000 | [diff] [blame] | 320 | case tok::at: |
Chris Lattner | c24278d | 2007-05-02 23:45:06 +0000 | [diff] [blame] | 321 | // @ is not a legal token unless objc is enabled, no need to check. |
Chris Lattner | b26b665 | 2006-11-08 06:10:32 +0000 | [diff] [blame] | 322 | ParseObjCAtDirectives(); |
Steve Naroff | b419d3a | 2006-10-27 23:18:49 +0000 | [diff] [blame] | 323 | return 0; |
| 324 | case tok::minus: |
Chris Lattner | c24278d | 2007-05-02 23:45:06 +0000 | [diff] [blame] | 325 | if (getLang().ObjC1) { |
| 326 | ParseObjCInstanceMethodDeclaration(); |
| 327 | } else { |
| 328 | Diag(Tok, diag::err_expected_external_declaration); |
| 329 | ConsumeToken(); |
| 330 | } |
Chris Lattner | aacc5af | 2006-11-03 07:21:07 +0000 | [diff] [blame] | 331 | return 0; |
Steve Naroff | b419d3a | 2006-10-27 23:18:49 +0000 | [diff] [blame] | 332 | case tok::plus: |
Chris Lattner | c24278d | 2007-05-02 23:45:06 +0000 | [diff] [blame] | 333 | if (getLang().ObjC1) { |
| 334 | ParseObjCClassMethodDeclaration(); |
| 335 | } else { |
| 336 | Diag(Tok, diag::err_expected_external_declaration); |
| 337 | ConsumeToken(); |
| 338 | } |
Steve Naroff | b419d3a | 2006-10-27 23:18:49 +0000 | [diff] [blame] | 339 | return 0; |
Chris Lattner | 302b4be | 2006-11-19 02:31:38 +0000 | [diff] [blame] | 340 | case tok::kw_typedef: |
| 341 | // A function definition cannot start with a 'typedef' keyword. |
| 342 | return ParseDeclaration(Declarator::FileContext); |
Chris Lattner | 0bb5f83 | 2006-07-31 01:59:18 +0000 | [diff] [blame] | 343 | default: |
| 344 | // We can't tell whether this is a function-definition or declaration yet. |
Chris Lattner | 2dacc3f | 2006-10-16 00:33:54 +0000 | [diff] [blame] | 345 | return ParseDeclarationOrFunctionDefinition(); |
Chris Lattner | 0bb5f83 | 2006-07-31 01:59:18 +0000 | [diff] [blame] | 346 | } |
| 347 | } |
| 348 | |
| 349 | /// ParseDeclarationOrFunctionDefinition - Parse either a function-definition or |
Chris Lattner | 70f32b7 | 2006-07-31 05:09:04 +0000 | [diff] [blame] | 350 | /// a declaration. We can't tell which we have until we read up to the |
| 351 | /// compound-statement in function-definition. |
Chris Lattner | 0bb5f83 | 2006-07-31 01:59:18 +0000 | [diff] [blame] | 352 | /// |
Chris Lattner | 70f32b7 | 2006-07-31 05:09:04 +0000 | [diff] [blame] | 353 | /// function-definition: [C99 6.9.1] |
| 354 | /// declaration-specifiers[opt] declarator declaration-list[opt] |
| 355 | /// compound-statement [TODO] |
| 356 | /// declaration: [C99 6.7] |
Chris Lattner | 0bb5f83 | 2006-07-31 01:59:18 +0000 | [diff] [blame] | 357 | /// declaration-specifiers init-declarator-list[opt] ';' [TODO] |
Chris Lattner | d9c3c59 | 2006-08-05 06:26:47 +0000 | [diff] [blame] | 358 | /// [!C99] init-declarator-list ';' [TODO] |
Chris Lattner | 70f32b7 | 2006-07-31 05:09:04 +0000 | [diff] [blame] | 359 | /// [OMP] threadprivate-directive [TODO] |
| 360 | /// |
Chris Lattner | 2dacc3f | 2006-10-16 00:33:54 +0000 | [diff] [blame] | 361 | Parser::DeclTy *Parser::ParseDeclarationOrFunctionDefinition() { |
Chris Lattner | 70f32b7 | 2006-07-31 05:09:04 +0000 | [diff] [blame] | 362 | // Parse the common declaration-specifiers piece. |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 363 | DeclSpec DS; |
| 364 | ParseDeclarationSpecifiers(DS); |
Chris Lattner | d286488 | 2006-08-05 08:09:44 +0000 | [diff] [blame] | 365 | |
| 366 | // C99 6.7.2.3p6: Handle "struct-or-union identifier;", "enum { X };" |
Chris Lattner | 53361ac | 2006-08-10 05:19:57 +0000 | [diff] [blame] | 367 | // declaration-specifiers init-declarator-list[opt] ';' |
Chris Lattner | 0e89462 | 2006-08-13 19:58:17 +0000 | [diff] [blame] | 368 | if (Tok.getKind() == tok::semi) { |
Chris Lattner | 0e89462 | 2006-08-13 19:58:17 +0000 | [diff] [blame] | 369 | ConsumeToken(); |
Chris Lattner | 200bdc3 | 2006-11-19 02:43:37 +0000 | [diff] [blame] | 370 | return Actions.ParsedFreeStandingDeclSpec(CurScope, DS); |
Chris Lattner | 0e89462 | 2006-08-13 19:58:17 +0000 | [diff] [blame] | 371 | } |
Chris Lattner | 70f32b7 | 2006-07-31 05:09:04 +0000 | [diff] [blame] | 372 | |
Steve Naroff | 1eb1ad6 | 2007-08-20 21:31:48 +0000 | [diff] [blame^] | 373 | // OBJC: This grammar hack allows prefix attributes on class interfaces. |
| 374 | if (Tok.getKind() == tok::at) { |
| 375 | SourceLocation AtLoc = ConsumeToken(); // the "@" |
| 376 | if (Tok.getIdentifierInfo()->getObjCKeywordID() == tok::objc_interface) |
| 377 | return ParseObjCAtInterfaceDeclaration(AtLoc, DS.getAttributes()); |
| 378 | } |
| 379 | |
Chris Lattner | fff824f | 2006-08-07 06:31:38 +0000 | [diff] [blame] | 380 | // Parse the first declarator. |
| 381 | Declarator DeclaratorInfo(DS, Declarator::FileContext); |
| 382 | ParseDeclarator(DeclaratorInfo); |
| 383 | // Error parsing the declarator? |
| 384 | if (DeclaratorInfo.getIdentifier() == 0) { |
| 385 | // If so, skip until the semi-colon or a }. |
| 386 | SkipUntil(tok::r_brace, true); |
| 387 | if (Tok.getKind() == tok::semi) |
| 388 | ConsumeToken(); |
Chris Lattner | 2dacc3f | 2006-10-16 00:33:54 +0000 | [diff] [blame] | 389 | return 0; |
Chris Lattner | fff824f | 2006-08-07 06:31:38 +0000 | [diff] [blame] | 390 | } |
Chris Lattner | 70f32b7 | 2006-07-31 05:09:04 +0000 | [diff] [blame] | 391 | |
Chris Lattner | fff824f | 2006-08-07 06:31:38 +0000 | [diff] [blame] | 392 | // If the declarator is the start of a function definition, handle it. |
| 393 | if (Tok.getKind() == tok::equal || // int X()= -> not a function def |
| 394 | Tok.getKind() == tok::comma || // int X(), -> not a function def |
Chris Lattner | 2dacc3f | 2006-10-16 00:33:54 +0000 | [diff] [blame] | 395 | Tok.getKind() == tok::semi || // int X(); -> not a function def |
Chris Lattner | fff824f | 2006-08-07 06:31:38 +0000 | [diff] [blame] | 396 | Tok.getKind() == tok::kw_asm || // int X() __asm__ -> not a fn def |
| 397 | Tok.getKind() == tok::kw___attribute) {// int X() __attr__ -> not a fn def |
| 398 | // FALL THROUGH. |
Chris Lattner | a11999d | 2006-10-15 22:34:45 +0000 | [diff] [blame] | 399 | } else if (DeclaratorInfo.isFunctionDeclarator() && |
Chris Lattner | fff824f | 2006-08-07 06:31:38 +0000 | [diff] [blame] | 400 | (Tok.getKind() == tok::l_brace || // int X() {} |
| 401 | isDeclarationSpecifier())) { // int X(f) int f; {} |
Chris Lattner | 2dacc3f | 2006-10-16 00:33:54 +0000 | [diff] [blame] | 402 | return ParseFunctionDefinition(DeclaratorInfo); |
Chris Lattner | fff824f | 2006-08-07 06:31:38 +0000 | [diff] [blame] | 403 | } else { |
Chris Lattner | a11999d | 2006-10-15 22:34:45 +0000 | [diff] [blame] | 404 | if (DeclaratorInfo.isFunctionDeclarator()) |
Chris Lattner | fff824f | 2006-08-07 06:31:38 +0000 | [diff] [blame] | 405 | Diag(Tok, diag::err_expected_fn_body); |
| 406 | else |
| 407 | Diag(Tok, diag::err_expected_after_declarator); |
Chris Lattner | e4e3859 | 2006-08-14 00:15:05 +0000 | [diff] [blame] | 408 | SkipUntil(tok::semi); |
Chris Lattner | 2dacc3f | 2006-10-16 00:33:54 +0000 | [diff] [blame] | 409 | return 0; |
Chris Lattner | fff824f | 2006-08-07 06:31:38 +0000 | [diff] [blame] | 410 | } |
Chris Lattner | d9c3c59 | 2006-08-05 06:26:47 +0000 | [diff] [blame] | 411 | |
Chris Lattner | 53361ac | 2006-08-10 05:19:57 +0000 | [diff] [blame] | 412 | // Parse the init-declarator-list for a normal declaration. |
Chris Lattner | 2dacc3f | 2006-10-16 00:33:54 +0000 | [diff] [blame] | 413 | return ParseInitDeclaratorListAfterFirstDeclarator(DeclaratorInfo); |
Chris Lattner | 70f32b7 | 2006-07-31 05:09:04 +0000 | [diff] [blame] | 414 | } |
| 415 | |
Chris Lattner | fff824f | 2006-08-07 06:31:38 +0000 | [diff] [blame] | 416 | /// ParseFunctionDefinition - We parsed and verified that the specified |
| 417 | /// Declarator is well formed. If this is a K&R-style function, read the |
| 418 | /// parameters declaration-list, then start the compound-statement. |
| 419 | /// |
| 420 | /// declaration-specifiers[opt] declarator declaration-list[opt] |
| 421 | /// compound-statement [TODO] |
| 422 | /// |
Chris Lattner | 2dacc3f | 2006-10-16 00:33:54 +0000 | [diff] [blame] | 423 | Parser::DeclTy *Parser::ParseFunctionDefinition(Declarator &D) { |
Chris Lattner | cbc426d | 2006-12-02 06:43:02 +0000 | [diff] [blame] | 424 | const DeclaratorChunk &FnTypeInfo = D.getTypeObject(0); |
| 425 | assert(FnTypeInfo.Kind == DeclaratorChunk::Function && |
Chris Lattner | fff824f | 2006-08-07 06:31:38 +0000 | [diff] [blame] | 426 | "This isn't a function declarator!"); |
Chris Lattner | 5c5fbcc | 2006-12-03 08:41:30 +0000 | [diff] [blame] | 427 | const DeclaratorChunk::FunctionTypeInfo &FTI = FnTypeInfo.Fun; |
Chris Lattner | fff824f | 2006-08-07 06:31:38 +0000 | [diff] [blame] | 428 | |
| 429 | // If this declaration was formed with a K&R-style identifier list for the |
| 430 | // arguments, parse declarations for all of the args next. |
| 431 | // int foo(a,b) int a; float b; {} |
Chris Lattner | 5c5fbcc | 2006-12-03 08:41:30 +0000 | [diff] [blame] | 432 | if (!FTI.hasPrototype && FTI.NumArgs != 0) |
| 433 | ParseKNRParamDeclarations(D); |
Chris Lattner | fff824f | 2006-08-07 06:31:38 +0000 | [diff] [blame] | 434 | |
Chris Lattner | 5c5fbcc | 2006-12-03 08:41:30 +0000 | [diff] [blame] | 435 | // Enter a scope for the function body. |
| 436 | EnterScope(Scope::FnScope); |
| 437 | |
Chris Lattner | 2114d5e | 2006-12-04 07:40:24 +0000 | [diff] [blame] | 438 | // Tell the actions module that we have entered a function definition with the |
| 439 | // specified Declarator for the function. |
Chris Lattner | 5c5fbcc | 2006-12-03 08:41:30 +0000 | [diff] [blame] | 440 | DeclTy *Res = Actions.ParseStartOfFunctionDef(CurScope, D); |
| 441 | |
| 442 | |
Chris Lattner | 0ccd51e | 2006-08-09 05:47:47 +0000 | [diff] [blame] | 443 | // We should have an opening brace now. |
| 444 | if (Tok.getKind() != tok::l_brace) { |
| 445 | Diag(Tok, diag::err_expected_fn_body); |
| 446 | |
| 447 | // Skip over garbage, until we get to '{'. Don't eat the '{'. |
| 448 | SkipUntil(tok::l_brace, true, true); |
| 449 | |
| 450 | // If we didn't find the '{', bail out. |
Chris Lattner | 5c5fbcc | 2006-12-03 08:41:30 +0000 | [diff] [blame] | 451 | if (Tok.getKind() != tok::l_brace) { |
| 452 | ExitScope(); |
Chris Lattner | 2dacc3f | 2006-10-16 00:33:54 +0000 | [diff] [blame] | 453 | return 0; |
Chris Lattner | 5c5fbcc | 2006-12-03 08:41:30 +0000 | [diff] [blame] | 454 | } |
Chris Lattner | 0ccd51e | 2006-08-09 05:47:47 +0000 | [diff] [blame] | 455 | } |
Chris Lattner | fff824f | 2006-08-07 06:31:38 +0000 | [diff] [blame] | 456 | |
Chris Lattner | 7f58c3d | 2007-01-21 06:56:16 +0000 | [diff] [blame] | 457 | // Do not enter a scope for the brace, as the arguments are in the same scope |
| 458 | // (the function body) as the body itself. Instead, just read the statement |
| 459 | // list and put it into a CompoundStmt for safe keeping. |
| 460 | StmtResult FnBody = ParseCompoundStatementBody(); |
Chris Lattner | 5c5fbcc | 2006-12-03 08:41:30 +0000 | [diff] [blame] | 461 | if (FnBody.isInvalid) { |
| 462 | ExitScope(); |
| 463 | return 0; |
| 464 | } |
Chris Lattner | 2dacc3f | 2006-10-16 00:33:54 +0000 | [diff] [blame] | 465 | |
Chris Lattner | 5c5fbcc | 2006-12-03 08:41:30 +0000 | [diff] [blame] | 466 | // Leave the function body scope. |
| 467 | ExitScope(); |
Chris Lattner | 7014fb8 | 2006-11-05 07:36:23 +0000 | [diff] [blame] | 468 | |
Chris Lattner | 2dacc3f | 2006-10-16 00:33:54 +0000 | [diff] [blame] | 469 | // TODO: Pass argument information. |
Chris Lattner | 229ce60 | 2006-11-21 01:21:07 +0000 | [diff] [blame] | 470 | return Actions.ParseFunctionDefBody(Res, FnBody.Val); |
Chris Lattner | fff824f | 2006-08-07 06:31:38 +0000 | [diff] [blame] | 471 | } |
| 472 | |
Chris Lattner | 5c5fbcc | 2006-12-03 08:41:30 +0000 | [diff] [blame] | 473 | /// ParseKNRParamDeclarations - Parse 'declaration-list[opt]' which provides |
| 474 | /// types for a function with a K&R-style identifier list for arguments. |
| 475 | void Parser::ParseKNRParamDeclarations(Declarator &D) { |
| 476 | // We know that the top-level of this declarator is a function. |
| 477 | DeclaratorChunk::FunctionTypeInfo &FTI = D.getTypeObject(0).Fun; |
| 478 | |
| 479 | // Read all the argument declarations. |
| 480 | while (isDeclarationSpecifier()) { |
| 481 | SourceLocation DSStart = Tok.getLocation(); |
| 482 | |
| 483 | // Parse the common declaration-specifiers piece. |
| 484 | DeclSpec DS; |
| 485 | ParseDeclarationSpecifiers(DS); |
| 486 | |
| 487 | // C99 6.9.1p6: 'each declaration in the declaration list shall have at |
| 488 | // least one declarator'. |
| 489 | // NOTE: GCC just makes this an ext-warn. It's not clear what it does with |
| 490 | // the declarations though. It's trivial to ignore them, really hard to do |
| 491 | // anything else with them. |
| 492 | if (Tok.getKind() == tok::semi) { |
| 493 | Diag(DSStart, diag::err_declaration_does_not_declare_param); |
| 494 | ConsumeToken(); |
| 495 | continue; |
| 496 | } |
| 497 | |
| 498 | // C99 6.9.1p6: Declarations shall contain no storage-class specifiers other |
| 499 | // than register. |
| 500 | if (DS.getStorageClassSpec() != DeclSpec::SCS_unspecified && |
| 501 | DS.getStorageClassSpec() != DeclSpec::SCS_register) { |
| 502 | Diag(DS.getStorageClassSpecLoc(), |
| 503 | diag::err_invalid_storage_class_in_func_decl); |
| 504 | DS.ClearStorageClassSpecs(); |
| 505 | } |
| 506 | if (DS.isThreadSpecified()) { |
| 507 | Diag(DS.getThreadSpecLoc(), |
| 508 | diag::err_invalid_storage_class_in_func_decl); |
| 509 | DS.ClearStorageClassSpecs(); |
| 510 | } |
| 511 | |
| 512 | // Parse the first declarator attached to this declspec. |
| 513 | Declarator ParmDeclarator(DS, Declarator::KNRTypeListContext); |
| 514 | ParseDeclarator(ParmDeclarator); |
| 515 | |
| 516 | // Handle the full declarator list. |
| 517 | while (1) { |
Steve Naroff | 0f2fe17 | 2007-06-01 17:11:19 +0000 | [diff] [blame] | 518 | DeclTy *AttrList; |
Chris Lattner | 5c5fbcc | 2006-12-03 08:41:30 +0000 | [diff] [blame] | 519 | // If attributes are present, parse them. |
| 520 | if (Tok.getKind() == tok::kw___attribute) |
| 521 | // FIXME: attach attributes too. |
Steve Naroff | 0f2fe17 | 2007-06-01 17:11:19 +0000 | [diff] [blame] | 522 | AttrList = ParseAttributes(); |
Chris Lattner | 5c5fbcc | 2006-12-03 08:41:30 +0000 | [diff] [blame] | 523 | |
| 524 | // Ask the actions module to compute the type for this declarator. |
| 525 | Action::TypeResult TR = |
| 526 | Actions.ParseParamDeclaratorType(CurScope, ParmDeclarator); |
| 527 | if (!TR.isInvalid && |
| 528 | // A missing identifier has already been diagnosed. |
| 529 | ParmDeclarator.getIdentifier()) { |
| 530 | |
| 531 | // Scan the argument list looking for the correct param to apply this |
| 532 | // type. |
| 533 | for (unsigned i = 0; ; ++i) { |
| 534 | // C99 6.9.1p6: those declarators shall declare only identifiers from |
| 535 | // the identifier list. |
| 536 | if (i == FTI.NumArgs) { |
| 537 | Diag(ParmDeclarator.getIdentifierLoc(), diag::err_no_matching_param, |
| 538 | ParmDeclarator.getIdentifier()->getName()); |
| 539 | break; |
| 540 | } |
| 541 | |
| 542 | if (FTI.ArgInfo[i].Ident == ParmDeclarator.getIdentifier()) { |
| 543 | // Reject redefinitions of parameters. |
| 544 | if (FTI.ArgInfo[i].TypeInfo) { |
| 545 | Diag(ParmDeclarator.getIdentifierLoc(), |
| 546 | diag::err_param_redefinition, |
| 547 | ParmDeclarator.getIdentifier()->getName()); |
| 548 | } else { |
| 549 | FTI.ArgInfo[i].TypeInfo = TR.Val; |
| 550 | } |
| 551 | break; |
| 552 | } |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | // If we don't have a comma, it is either the end of the list (a ';') or |
| 557 | // an error, bail out. |
| 558 | if (Tok.getKind() != tok::comma) |
| 559 | break; |
| 560 | |
| 561 | // Consume the comma. |
| 562 | ConsumeToken(); |
| 563 | |
| 564 | // Parse the next declarator. |
| 565 | ParmDeclarator.clear(); |
| 566 | ParseDeclarator(ParmDeclarator); |
| 567 | } |
| 568 | |
| 569 | if (Tok.getKind() == tok::semi) { |
| 570 | ConsumeToken(); |
| 571 | } else { |
| 572 | Diag(Tok, diag::err_parse_error); |
| 573 | // Skip to end of block or statement |
| 574 | SkipUntil(tok::semi, true); |
| 575 | if (Tok.getKind() == tok::semi) |
| 576 | ConsumeToken(); |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | // The actions module must verify that all arguments were declared. |
| 581 | } |
| 582 | |
| 583 | |
Chris Lattner | 0116c47 | 2006-08-15 06:03:28 +0000 | [diff] [blame] | 584 | /// ParseAsmStringLiteral - This is just a normal string-literal, but is not |
| 585 | /// allowed to be a wide string, and is not subject to character translation. |
| 586 | /// |
| 587 | /// [GNU] asm-string-literal: |
| 588 | /// string-literal |
| 589 | /// |
| 590 | void Parser::ParseAsmStringLiteral() { |
Chris Lattner | d3e9895 | 2006-10-06 05:22:26 +0000 | [diff] [blame] | 591 | if (!isTokenStringLiteral()) { |
Chris Lattner | 0116c47 | 2006-08-15 06:03:28 +0000 | [diff] [blame] | 592 | Diag(Tok, diag::err_expected_string_literal); |
| 593 | return; |
| 594 | } |
| 595 | |
| 596 | ExprResult Res = ParseStringLiteralExpression(); |
| 597 | if (Res.isInvalid) return; |
| 598 | |
| 599 | // TODO: Diagnose: wide string literal in 'asm' |
| 600 | } |
| 601 | |
Chris Lattner | 6d7e634 | 2006-08-15 03:41:14 +0000 | [diff] [blame] | 602 | /// ParseSimpleAsm |
| 603 | /// |
| 604 | /// [GNU] simple-asm-expr: |
| 605 | /// 'asm' '(' asm-string-literal ')' |
Chris Lattner | 6d7e634 | 2006-08-15 03:41:14 +0000 | [diff] [blame] | 606 | /// |
| 607 | void Parser::ParseSimpleAsm() { |
| 608 | assert(Tok.getKind() == tok::kw_asm && "Not an asm!"); |
| 609 | ConsumeToken(); |
| 610 | |
| 611 | if (Tok.getKind() != tok::l_paren) { |
| 612 | Diag(Tok, diag::err_expected_lparen_after, "asm"); |
| 613 | return; |
| 614 | } |
| 615 | |
Chris Lattner | 0413237 | 2006-10-16 06:12:55 +0000 | [diff] [blame] | 616 | SourceLocation Loc = ConsumeParen(); |
Chris Lattner | 6d7e634 | 2006-08-15 03:41:14 +0000 | [diff] [blame] | 617 | |
Chris Lattner | 0116c47 | 2006-08-15 06:03:28 +0000 | [diff] [blame] | 618 | ParseAsmStringLiteral(); |
Chris Lattner | 6d7e634 | 2006-08-15 03:41:14 +0000 | [diff] [blame] | 619 | |
Chris Lattner | 04f8019 | 2006-08-15 04:55:54 +0000 | [diff] [blame] | 620 | MatchRHSPunctuation(tok::r_paren, Loc); |
Chris Lattner | 6d7e634 | 2006-08-15 03:41:14 +0000 | [diff] [blame] | 621 | } |
Steve Naroff | b419d3a | 2006-10-27 23:18:49 +0000 | [diff] [blame] | 622 | |