PPExpressions.cpp (218893) | PPExpressions.cpp (221345) |
---|---|
1//===--- PPExpressions.cpp - Preprocessor Expression Evaluation -----------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// --- 166 unchanged lines hidden (view full) --- 175 PP.LexNonComment(PeekTok); 176 return false; 177 } 178 179 switch (PeekTok.getKind()) { 180 default: // Non-value token. 181 PP.Diag(PeekTok, diag::err_pp_expr_bad_token_start_expr); 182 return true; | 1//===--- PPExpressions.cpp - Preprocessor Expression Evaluation -----------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// --- 166 unchanged lines hidden (view full) --- 175 PP.LexNonComment(PeekTok); 176 return false; 177 } 178 179 switch (PeekTok.getKind()) { 180 default: // Non-value token. 181 PP.Diag(PeekTok, diag::err_pp_expr_bad_token_start_expr); 182 return true; |
183 case tok::eom: | 183 case tok::eod: |
184 case tok::r_paren: 185 // If there is no expression, report and exit. 186 PP.Diag(PeekTok, diag::err_pp_expected_value_in_expr); 187 return true; 188 case tok::numeric_constant: { 189 llvm::SmallString<64> IntegerBuffer; 190 bool NumberInvalid = false; 191 llvm::StringRef Spelling = PP.getSpelling(PeekTok, IntegerBuffer, --- 175 unchanged lines hidden (view full) --- 367} 368 369 370 371/// getPrecedence - Return the precedence of the specified binary operator 372/// token. This returns: 373/// ~0 - Invalid token. 374/// 14 -> 3 - various operators. | 184 case tok::r_paren: 185 // If there is no expression, report and exit. 186 PP.Diag(PeekTok, diag::err_pp_expected_value_in_expr); 187 return true; 188 case tok::numeric_constant: { 189 llvm::SmallString<64> IntegerBuffer; 190 bool NumberInvalid = false; 191 llvm::StringRef Spelling = PP.getSpelling(PeekTok, IntegerBuffer, --- 175 unchanged lines hidden (view full) --- 367} 368 369 370 371/// getPrecedence - Return the precedence of the specified binary operator 372/// token. This returns: 373/// ~0 - Invalid token. 374/// 14 -> 3 - various operators. |
375/// 0 - 'eom' or ')' | 375/// 0 - 'eod' or ')' |
376static unsigned getPrecedence(tok::TokenKind Kind) { 377 switch (Kind) { 378 default: return ~0U; 379 case tok::percent: 380 case tok::slash: 381 case tok::star: return 14; 382 case tok::plus: 383 case tok::minus: return 13; --- 8 unchanged lines hidden (view full) --- 392 case tok::amp: return 9; 393 case tok::caret: return 8; 394 case tok::pipe: return 7; 395 case tok::ampamp: return 6; 396 case tok::pipepipe: return 5; 397 case tok::question: return 4; 398 case tok::comma: return 3; 399 case tok::colon: return 2; | 376static unsigned getPrecedence(tok::TokenKind Kind) { 377 switch (Kind) { 378 default: return ~0U; 379 case tok::percent: 380 case tok::slash: 381 case tok::star: return 14; 382 case tok::plus: 383 case tok::minus: return 13; --- 8 unchanged lines hidden (view full) --- 392 case tok::amp: return 9; 393 case tok::caret: return 8; 394 case tok::pipe: return 7; 395 case tok::ampamp: return 6; 396 case tok::pipepipe: return 5; 397 case tok::question: return 4; 398 case tok::comma: return 3; 399 case tok::colon: return 2; |
400 case tok::r_paren: return 0; // Lowest priority, end of expr. 401 case tok::eom: return 0; // Lowest priority, end of macro. | 400 case tok::r_paren: return 0;// Lowest priority, end of expr. 401 case tok::eod: return 0;// Lowest priority, end of directive. |
402 } 403} 404 405 406/// EvaluateDirectiveSubExpr - Evaluate the subexpression whose first token is 407/// PeekTok, and whose precedence is PeekPrec. This returns the result in LHS. 408/// 409/// If ValueLive is false, then this value is being evaluated in a context where --- 298 unchanged lines hidden (view full) --- 708 709 // C99 6.10.1p3 - All expressions are evaluated as intmax_t or uintmax_t. 710 unsigned BitWidth = getTargetInfo().getIntMaxTWidth(); 711 712 PPValue ResVal(BitWidth); 713 DefinedTracker DT; 714 if (EvaluateValue(ResVal, Tok, DT, true, *this)) { 715 // Parse error, skip the rest of the macro line. | 402 } 403} 404 405 406/// EvaluateDirectiveSubExpr - Evaluate the subexpression whose first token is 407/// PeekTok, and whose precedence is PeekPrec. This returns the result in LHS. 408/// 409/// If ValueLive is false, then this value is being evaluated in a context where --- 298 unchanged lines hidden (view full) --- 708 709 // C99 6.10.1p3 - All expressions are evaluated as intmax_t or uintmax_t. 710 unsigned BitWidth = getTargetInfo().getIntMaxTWidth(); 711 712 PPValue ResVal(BitWidth); 713 DefinedTracker DT; 714 if (EvaluateValue(ResVal, Tok, DT, true, *this)) { 715 // Parse error, skip the rest of the macro line. |
716 if (Tok.isNot(tok::eom)) | 716 if (Tok.isNot(tok::eod)) |
717 DiscardUntilEndOfDirective(); 718 719 // Restore 'DisableMacroExpansion'. 720 DisableMacroExpansion = DisableMacroExpansionAtStartOfDirective; 721 return false; 722 } 723 724 // If we are at the end of the expression after just parsing a value, there 725 // must be no (unparenthesized) binary operators involved, so we can exit 726 // directly. | 717 DiscardUntilEndOfDirective(); 718 719 // Restore 'DisableMacroExpansion'. 720 DisableMacroExpansion = DisableMacroExpansionAtStartOfDirective; 721 return false; 722 } 723 724 // If we are at the end of the expression after just parsing a value, there 725 // must be no (unparenthesized) binary operators involved, so we can exit 726 // directly. |
727 if (Tok.is(tok::eom)) { | 727 if (Tok.is(tok::eod)) { |
728 // If the expression we parsed was of the form !defined(macro), return the 729 // macro in IfNDefMacro. 730 if (DT.State == DefinedTracker::NotDefinedMacro) 731 IfNDefMacro = DT.TheMacro; 732 733 // Restore 'DisableMacroExpansion'. 734 DisableMacroExpansion = DisableMacroExpansionAtStartOfDirective; 735 return ResVal.Val != 0; 736 } 737 738 // Otherwise, we must have a binary operator (e.g. "#if 1 < 2"), so parse the 739 // operator and the stuff after it. 740 if (EvaluateDirectiveSubExpr(ResVal, getPrecedence(tok::question), 741 Tok, true, *this)) { 742 // Parse error, skip the rest of the macro line. | 728 // If the expression we parsed was of the form !defined(macro), return the 729 // macro in IfNDefMacro. 730 if (DT.State == DefinedTracker::NotDefinedMacro) 731 IfNDefMacro = DT.TheMacro; 732 733 // Restore 'DisableMacroExpansion'. 734 DisableMacroExpansion = DisableMacroExpansionAtStartOfDirective; 735 return ResVal.Val != 0; 736 } 737 738 // Otherwise, we must have a binary operator (e.g. "#if 1 < 2"), so parse the 739 // operator and the stuff after it. 740 if (EvaluateDirectiveSubExpr(ResVal, getPrecedence(tok::question), 741 Tok, true, *this)) { 742 // Parse error, skip the rest of the macro line. |
743 if (Tok.isNot(tok::eom)) | 743 if (Tok.isNot(tok::eod)) |
744 DiscardUntilEndOfDirective(); 745 746 // Restore 'DisableMacroExpansion'. 747 DisableMacroExpansion = DisableMacroExpansionAtStartOfDirective; 748 return false; 749 } 750 | 744 DiscardUntilEndOfDirective(); 745 746 // Restore 'DisableMacroExpansion'. 747 DisableMacroExpansion = DisableMacroExpansionAtStartOfDirective; 748 return false; 749 } 750 |
751 // If we aren't at the tok::eom token, something bad happened, like an extra | 751 // If we aren't at the tok::eod token, something bad happened, like an extra |
752 // ')' token. | 752 // ')' token. |
753 if (Tok.isNot(tok::eom)) { | 753 if (Tok.isNot(tok::eod)) { |
754 Diag(Tok, diag::err_pp_expected_eol); 755 DiscardUntilEndOfDirective(); 756 } 757 758 // Restore 'DisableMacroExpansion'. 759 DisableMacroExpansion = DisableMacroExpansionAtStartOfDirective; 760 return ResVal.Val != 0; 761} 762 | 754 Diag(Tok, diag::err_pp_expected_eol); 755 DiscardUntilEndOfDirective(); 756 } 757 758 // Restore 'DisableMacroExpansion'. 759 DisableMacroExpansion = DisableMacroExpansionAtStartOfDirective; 760 return ResVal.Val != 0; 761} 762 |