Commit 9a1b49f7 by Jamie Madill

Revert "Don't evaluate short-circuited preprocessor expressions"

Build break on Clang: FAILED: /b/build/goma/gomacc ../../third_party/llvm-build/Release+Asserts/bin/clang++ -MMD -MF obj/third_party/angle/src/compiler/preprocessor/preprocessor.ExpressionParser.o.d -DV8_DEPRECATION_WARNINGS -DCLD_VERSION=2 -D__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORE=0 -DCHROMIUM_BUILD -DCR_CLANG_REVISION=245965-1 -DUSE_LIBJPEG_TURBO=1 -DENABLE_ONE_CLICK_SIGNIN -DENABLE_PRE_SYNC_BACKUP -DENABLE_WEBRTC=1 -DENABLE_MEDIA_ROUTER=1 -DUSE_PROPRIETARY_CODECS -DENABLE_PEPPER_CDMS -DENABLE_CONFIGURATION_POLICY -DENABLE_NOTIFICATIONS -DENABLE_HIDPI=1 -DSYSTEM_NATIVELY_SIGNALS_MEMORY_PRESSURE -DDONT_EMBED_BUILD_METADATA -DDCHECK_ALWAYS_ON=1 -DFIELDTRIAL_TESTING_ENABLED -DENABLE_TASK_MANAGER=1 -DENABLE_EXTENSIONS=1 -DENABLE_PDF=1 -DENABLE_PLUGIN_INSTALLATION=1 -DENABLE_PLUGINS=1 -DENABLE_SESSION_SERVICE=1 -DENABLE_THEMES=1 -DENABLE_AUTOFILL_DIALOG=1 -DENABLE_BACKGROUND=1 -DENABLE_GOOGLE_NOW=1 -DENABLE_PRINTING=1 -DENABLE_BASIC_PRINTING=1 -DENABLE_PRINT_PREVIEW=1 -DENABLE_SPELLCHECK=1 -DUSE_BROWSER_SPELLCHECKER=1 -DENABLE_CAPTIVE_PORTAL_DETECTION=1 -DENABLE_APP_LIST=1 -DENABLE_SETTINGS_APP=1 -DENABLE_SUPERVISED_USERS=1 -DENABLE_SERVICE_DISCOVERY=1 -DENABLE_WIFI_BOOTSTRAPPING=1 -DV8_USE_EXTERNAL_STARTUP_DATA -DFULL_SAFE_BROWSING -DSAFE_BROWSING_CSD -DSAFE_BROWSING_DB_LOCAL -DSAFE_BROWSING_SERVICE -DUSE_LIBPCI=1 -DUSE_OPENSSL=1 -DNDEBUG -DNVALGRIND -DDYNAMIC_ANNOTATIONS_ENABLED=0 -Igen -isysroot /Applications/Xcode5.1.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -O2 -gdwarf-2 -fvisibility=hidden -Werror -Wnewline-eof -mmacosx-version-min=10.6 -arch x86_64 -Wendif-labels -Wno-unused-parameter -Wno-missing-field-initializers -Wno-selector-type-mismatch -Wpartial-availability -Wheader-hygiene -Wno-char-subscripts -Wno-unneeded-internal-declaration -Wno-covered-switch-default -Wstring-conversion -Wno-c++11-narrowing -Wno-deprecated-register -Wno-inconsistent-missing-override -Wno-shift-negative-value -Wno-unused-function -Wno-unused-variable -std=c++11 -fno-rtti -fno-exceptions -fvisibility-inlines-hidden -fno-threadsafe-statics -Xclang -load -Xclang /b/build/slave/GPU_Mac_Builder/build/src/third_party/llvm-build/Release+Asserts/lib/libFindBadConstructs.dylib -Xclang -add-plugin -Xclang find-bad-constructs -Xclang -plugin-arg-find-bad-constructs -Xclang check-templates -fcolor-diagnostics -fno-strict-aliasing -c ../../third_party/angle/src/compiler/preprocessor/ExpressionParser.cpp -o obj/third_party/angle/src/compiler/preprocessor/preprocessor.ExpressionParser.o ../../third_party/angle/src/compiler/preprocessor/ExpressionParser.cpp:1372:35: error: use of logical '||' with constant operand [-Werror,-Wconstant-logical-operand] (yyval) = (yyvsp[-3]) || 0; ^ ~ ../../third_party/angle/src/compiler/preprocessor/ExpressionParser.cpp:1372:35: note: use '|' for a bitwise operation (yyval) = (yyvsp[-3]) || 0; ^~ | ../../third_party/angle/src/compiler/preprocessor/ExpressionParser.cpp:1406:35: error: use of logical '&&' with constant operand [-Werror,-Wconstant-logical-operand] (yyval) = (yyvsp[-3]) && 0; ^ ~ ../../third_party/angle/src/compiler/preprocessor/ExpressionParser.cpp:1406:35: note: use '&' for a bitwise operation (yyval) = (yyvsp[-3]) && 0; ^~ & ../../third_party/angle/src/compiler/preprocessor/ExpressionParser.cpp:1406:35: note: remove constant to silence this warning (yyval) = (yyvsp[-3]) && 0; ~^~~~ BUG=angleproject:347 This reverts commit 6ffe6135. Change-Id: I6d81666cca573f320bfb1164a6c794b6f75f7463 Reviewed-on: https://chromium-review.googlesource.com/298020Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 47f730fa
......@@ -122,13 +122,6 @@ struct Context
pp::Lexer* lexer;
pp::Token* token;
int* result;
void startIgnoreErrors() { ++ignoreErrors; }
void endIgnoreErrors() { --ignoreErrors; }
bool isIgnoringErrors() { return ignoreErrors > 0; }
int ignoreErrors;
};
} // namespace
......@@ -169,16 +162,15 @@ extern int ppdebug;
enum yytokentype
{
TOK_CONST_INT = 258,
TOK_IDENTIFIER = 259,
TOK_OP_OR = 260,
TOK_OP_AND = 261,
TOK_OP_EQ = 262,
TOK_OP_NE = 263,
TOK_OP_LE = 264,
TOK_OP_GE = 265,
TOK_OP_LEFT = 266,
TOK_OP_RIGHT = 267,
TOK_UNARY = 268
TOK_OP_OR = 259,
TOK_OP_AND = 260,
TOK_OP_EQ = 261,
TOK_OP_NE = 262,
TOK_OP_LE = 263,
TOK_OP_GE = 264,
TOK_OP_LEFT = 265,
TOK_OP_RIGHT = 266,
TOK_UNARY = 267
};
#endif
......@@ -437,23 +429,23 @@ union yyalloc
#endif /* !YYCOPY_NEEDED */
/* YYFINAL -- State number of the termination state. */
#define YYFINAL 15
#define YYFINAL 14
/* YYLAST -- Last index in YYTABLE. */
#define YYLAST 176
#define YYLAST 175
/* YYNTOKENS -- Number of terminals. */
#define YYNTOKENS 28
#define YYNTOKENS 27
/* YYNNTS -- Number of nonterminals. */
#define YYNNTS 5
#define YYNNTS 3
/* YYNRULES -- Number of rules. */
#define YYNRULES 29
#define YYNRULES 26
/* YYNSTATES -- Number of states. */
#define YYNSTATES 55
#define YYNSTATES 52
/* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned
by yylex, with out-of-bounds checking. */
#define YYUNDEFTOK 2
#define YYMAXUTOK 268
#define YYMAXUTOK 267
#define YYTRANSLATE(YYX) \
((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
......@@ -465,16 +457,16 @@ static const yytype_uint8 yytranslate[] =
0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 24, 2, 2, 2, 22, 9, 2,
26, 27, 20, 18, 2, 19, 2, 21, 2, 2,
2, 2, 2, 23, 2, 2, 2, 21, 8, 2,
25, 26, 19, 17, 2, 18, 2, 20, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
12, 2, 13, 2, 2, 2, 2, 2, 2, 2,
11, 2, 12, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 8, 2, 2, 2, 2, 2,
2, 2, 2, 2, 7, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 7, 2, 25, 2, 2, 2,
2, 2, 2, 2, 6, 2, 24, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
......@@ -488,16 +480,16 @@ static const yytype_uint8 yytranslate[] =
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
5, 6, 10, 11, 14, 15, 16, 17, 23
5, 9, 10, 13, 14, 15, 16, 22
};
#if YYDEBUG
/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
static const yytype_uint16 yyrline[] =
static const yytype_uint8 yyrline[] =
{
0, 105, 105, 111, 112, 118, 118, 141, 141, 164,
167, 170, 173, 176, 179, 182, 185, 188, 191, 194,
197, 200, 203, 226, 249, 252, 255, 258, 261, 264
0, 97, 97, 104, 105, 108, 111, 114, 117, 120,
123, 126, 129, 132, 135, 138, 141, 144, 147, 150,
163, 176, 179, 182, 185, 188, 191
};
#endif
......@@ -506,11 +498,11 @@ static const yytype_uint16 yyrline[] =
First, the terminals, then, starting at YYNTOKENS, nonterminals. */
static const char *const yytname[] =
{
"$end", "error", "$undefined", "TOK_CONST_INT", "TOK_IDENTIFIER",
"TOK_OP_OR", "TOK_OP_AND", "'|'", "'^'", "'&'", "TOK_OP_EQ", "TOK_OP_NE",
"'<'", "'>'", "TOK_OP_LE", "TOK_OP_GE", "TOK_OP_LEFT", "TOK_OP_RIGHT",
"'+'", "'-'", "'*'", "'/'", "'%'", "TOK_UNARY", "'!'", "'~'", "'('",
"')'", "$accept", "input", "expression", "$@1", "$@2", YY_NULLPTR
"$end", "error", "$undefined", "TOK_CONST_INT", "TOK_OP_OR",
"TOK_OP_AND", "'|'", "'^'", "'&'", "TOK_OP_EQ", "TOK_OP_NE", "'<'",
"'>'", "TOK_OP_LE", "TOK_OP_GE", "TOK_OP_LEFT", "TOK_OP_RIGHT", "'+'",
"'-'", "'*'", "'/'", "'%'", "TOK_UNARY", "'!'", "'~'", "'('", "')'",
"$accept", "input", "expression", YY_NULLPTR
};
#endif
......@@ -519,16 +511,16 @@ static const char *const yytname[] =
(internal) symbol number NUM (which must be that of a token). */
static const yytype_uint16 yytoknum[] =
{
0, 256, 257, 258, 259, 260, 261, 124, 94, 38,
262, 263, 60, 62, 264, 265, 266, 267, 43, 45,
42, 47, 37, 268, 33, 126, 40, 41
0, 256, 257, 258, 259, 260, 124, 94, 38, 261,
262, 60, 62, 263, 264, 265, 266, 43, 45, 42,
47, 37, 267, 33, 126, 40, 41
};
# endif
#define YYPACT_NINF -12
#define YYPACT_NINF -11
#define yypact_value_is_default(Yystate) \
(!!((Yystate) == (-12)))
(!!((Yystate) == (-11)))
#define YYTABLE_NINF -1
......@@ -539,12 +531,12 @@ static const yytype_uint16 yytoknum[] =
STATE-NUM. */
static const yytype_int16 yypact[] =
{
31, -12, -12, 31, 31, 31, 31, 31, 51, 76,
-12, -12, -12, -12, 53, -12, -12, -12, 31, 31,
31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
31, 31, 31, 31, -12, 31, 31, 124, 138, 26,
149, 149, -11, -11, -11, -11, 154, 154, -8, -8,
-12, -12, -12, 93, 109
46, -11, 46, 46, 46, 46, 46, 12, 68, -11,
-11, -11, -11, 27, -11, 46, 46, 46, 46, 46,
46, 46, 46, 46, 46, 46, 46, 46, 46, 46,
46, 46, 46, -11, 85, 101, 116, 130, 143, 154,
154, -10, -10, -10, -10, 37, 37, 31, 31, -11,
-11, -11
};
/* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
......@@ -552,24 +544,24 @@ static const yytype_int16 yypact[] =
means the default is an error. */
static const yytype_uint8 yydefact[] =
{
0, 3, 4, 0, 0, 0, 0, 0, 0, 2,
28, 27, 25, 26, 0, 1, 5, 7, 0, 0,
0, 3, 0, 0, 0, 0, 0, 0, 2, 25,
24, 22, 23, 0, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 29, 0, 0, 9, 10, 11,
13, 12, 17, 16, 15, 14, 19, 18, 21, 20,
24, 23, 22, 6, 8
0, 0, 0, 26, 4, 5, 6, 7, 8, 10,
9, 14, 13, 12, 11, 16, 15, 18, 17, 21,
20, 19
};
/* YYPGOTO[NTERM-NUM]. */
static const yytype_int8 yypgoto[] =
{
-12, -12, -3, -12, -12
-11, -11, -2
};
/* YYDEFGOTO[NTERM-NUM]. */
static const yytype_int8 yydefgoto[] =
{
-1, 8, 9, 35, 36
-1, 7, 8
};
/* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
......@@ -577,74 +569,74 @@ static const yytype_int8 yydefgoto[] =
number is the opposite. If YYTABLE_NINF, syntax error. */
static const yytype_uint8 yytable[] =
{
10, 11, 12, 13, 14, 27, 28, 29, 30, 31,
32, 33, 31, 32, 33, 37, 38, 39, 40, 41,
42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
52, 0, 53, 54, 1, 2, 21, 22, 23, 24,
25, 26, 27, 28, 29, 30, 31, 32, 33, 3,
4, 15, 0, 0, 0, 5, 6, 7, 16, 17,
18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
28, 29, 30, 31, 32, 33, 0, 0, 0, 0,
34, 16, 17, 18, 19, 20, 21, 22, 23, 24,
25, 26, 27, 28, 29, 30, 31, 32, 33, 17,
18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
28, 29, 30, 31, 32, 33, 18, 19, 20, 21,
22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 19, 20, 21, 22, 23, 24, 25, 26,
27, 28, 29, 30, 31, 32, 33, 20, 21, 22,
9, 10, 11, 12, 13, 26, 27, 28, 29, 30,
31, 32, 14, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
51, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32, 1,
30, 31, 32, 33, 28, 29, 30, 31, 32, 0,
0, 0, 0, 2, 3, 0, 0, 0, 0, 4,
5, 6, 15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
33, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 29, 30, 31, 32, 33
16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
26, 27, 28, 29, 30, 31, 32, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
30, 31, 32, 18, 19, 20, 21, 22, 23, 24,
25, 26, 27, 28, 29, 30, 31, 32, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
31, 32, 20, 21, 22, 23, 24, 25, 26, 27,
28, 29, 30, 31, 32, 22, 23, 24, 25, 26,
27, 28, 29, 30, 31, 32
};
static const yytype_int8 yycheck[] =
{
3, 4, 5, 6, 7, 16, 17, 18, 19, 20,
21, 22, 20, 21, 22, 18, 19, 20, 21, 22,
23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
33, -1, 35, 36, 3, 4, 10, 11, 12, 13,
14, 15, 16, 17, 18, 19, 20, 21, 22, 18,
19, 0, -1, -1, -1, 24, 25, 26, 5, 6,
7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, -1, -1, -1, -1,
27, 5, 6, 7, 8, 9, 10, 11, 12, 13,
14, 15, 16, 17, 18, 19, 20, 21, 22, 6,
7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 9, 10, 11,
2, 3, 4, 5, 6, 15, 16, 17, 18, 19,
20, 21, 0, 15, 16, 17, 18, 19, 20, 21,
22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 3,
19, 20, 21, 26, 17, 18, 19, 20, 21, -1,
-1, -1, -1, 17, 18, -1, -1, -1, -1, 23,
24, 25, 4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
22, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 18, 19, 20, 21, 22
5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 6, 7, 8,
9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
19, 20, 21, 7, 8, 9, 10, 11, 12, 13,
14, 15, 16, 17, 18, 19, 20, 21, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21
};
/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
symbol of state STATE-NUM. */
static const yytype_uint8 yystos[] =
{
0, 3, 4, 18, 19, 24, 25, 26, 29, 30,
30, 30, 30, 30, 30, 0, 5, 6, 7, 8,
0, 3, 17, 18, 23, 24, 25, 28, 29, 29,
29, 29, 29, 29, 0, 4, 5, 6, 7, 8,
9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
19, 20, 21, 22, 27, 31, 32, 30, 30, 30,
30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
30, 30, 30, 30, 30
19, 20, 21, 26, 29, 29, 29, 29, 29, 29,
29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
29, 29
};
/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
static const yytype_uint8 yyr1[] =
{
0, 28, 29, 30, 30, 31, 30, 32, 30, 30,
30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
30, 30, 30, 30, 30, 30, 30, 30, 30, 30
0, 27, 28, 29, 29, 29, 29, 29, 29, 29,
29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
29, 29, 29, 29, 29, 29, 29
};
/* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
static const yytype_uint8 yyr2[] =
{
0, 2, 1, 1, 1, 0, 4, 0, 4, 3,
0, 2, 1, 1, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 2, 2, 2, 2, 3
3, 3, 2, 2, 2, 2, 3
};
......@@ -1330,6 +1322,7 @@ yyreduce:
{
*(context->result) = static_cast<int>((yyvsp[0]));
YYACCEPT;
}
break;
......@@ -1337,10 +1330,7 @@ yyreduce:
case 4:
{
if (!context->isIgnoringErrors())
{
YYABORT;
}
(yyval) = (yyvsp[-2]) || (yyvsp[0]);
}
break;
......@@ -1348,15 +1338,7 @@ yyreduce:
case 5:
{
if ((yyvsp[-1]) != 0)
{
// Ignore errors in the short-circuited part of the expression.
// ESSL3.00 section 3.4:
// If an operand is not evaluated, the presence of undefined identifiers
// in the operand will not cause an error.
// Unevaluated division by zero should not cause an error either.
context->startIgnoreErrors();
}
(yyval) = (yyvsp[-2]) && (yyvsp[0]);
}
break;
......@@ -1364,64 +1346,12 @@ yyreduce:
case 6:
{
if ((yyvsp[-3]) != 0)
{
context->endIgnoreErrors();
// Make sure that short-circuited version of || works consistently
// with the normal version even for values other than 0 and 1.
(yyval) = (yyvsp[-3]) || 0;
}
else
{
(yyval) = (yyvsp[-3]) || (yyvsp[0]);
}
}
break;
case 7:
{
if ((yyvsp[-1]) == 0)
{
// Ignore errors in the short-circuited part of the expression.
// ESSL3.00 section 3.4:
// If an operand is not evaluated, the presence of undefined identifiers
// in the operand will not cause an error.
// Unevaluated division by zero should not cause an error either.
context->startIgnoreErrors();
}
}
break;
case 8:
{
if ((yyvsp[-3]) == 0)
{
context->endIgnoreErrors();
// Make sure that short-circuited version of && works consistently
// with the normal version even for values other than 0 and 1.
(yyval) = (yyvsp[-3]) && 0;
}
else
{
(yyval) = (yyvsp[-3]) && (yyvsp[0]);
}
}
break;
case 9:
{
(yyval) = (yyvsp[-2]) | (yyvsp[0]);
}
break;
case 10:
case 7:
{
(yyval) = (yyvsp[-2]) ^ (yyvsp[0]);
......@@ -1429,7 +1359,7 @@ yyreduce:
break;
case 11:
case 8:
{
(yyval) = (yyvsp[-2]) & (yyvsp[0]);
......@@ -1437,7 +1367,7 @@ yyreduce:
break;
case 12:
case 9:
{
(yyval) = (yyvsp[-2]) != (yyvsp[0]);
......@@ -1445,7 +1375,7 @@ yyreduce:
break;
case 13:
case 10:
{
(yyval) = (yyvsp[-2]) == (yyvsp[0]);
......@@ -1453,7 +1383,7 @@ yyreduce:
break;
case 14:
case 11:
{
(yyval) = (yyvsp[-2]) >= (yyvsp[0]);
......@@ -1461,7 +1391,7 @@ yyreduce:
break;
case 15:
case 12:
{
(yyval) = (yyvsp[-2]) <= (yyvsp[0]);
......@@ -1469,7 +1399,7 @@ yyreduce:
break;
case 16:
case 13:
{
(yyval) = (yyvsp[-2]) > (yyvsp[0]);
......@@ -1477,7 +1407,7 @@ yyreduce:
break;
case 17:
case 14:
{
(yyval) = (yyvsp[-2]) < (yyvsp[0]);
......@@ -1485,7 +1415,7 @@ yyreduce:
break;
case 18:
case 15:
{
(yyval) = (yyvsp[-2]) >> (yyvsp[0]);
......@@ -1493,7 +1423,7 @@ yyreduce:
break;
case 19:
case 16:
{
(yyval) = (yyvsp[-2]) << (yyvsp[0]);
......@@ -1501,7 +1431,7 @@ yyreduce:
break;
case 20:
case 17:
{
(yyval) = (yyvsp[-2]) - (yyvsp[0]);
......@@ -1509,7 +1439,7 @@ yyreduce:
break;
case 21:
case 18:
{
(yyval) = (yyvsp[-2]) + (yyvsp[0]);
......@@ -1517,63 +1447,43 @@ yyreduce:
break;
case 22:
case 19:
{
if ((yyvsp[0]) == 0)
{
if (context->isIgnoringErrors())
{
(yyval) = static_cast<YYSTYPE>(0);
}
else
{
std::ostringstream stream;
stream << (yyvsp[-2]) << " % " << (yyvsp[0]);
std::string text = stream.str();
context->diagnostics->report(pp::Diagnostics::PP_DIVISION_BY_ZERO,
context->token->location,
text.c_str());
YYABORT;
}
}
else
{
if ((yyvsp[0]) == 0) {
std::ostringstream stream;
stream << (yyvsp[-2]) << " % " << (yyvsp[0]);
std::string text = stream.str();
context->diagnostics->report(pp::Diagnostics::PP_DIVISION_BY_ZERO,
context->token->location,
text.c_str());
YYABORT;
} else {
(yyval) = (yyvsp[-2]) % (yyvsp[0]);
}
}
break;
case 23:
case 20:
{
if ((yyvsp[0]) == 0)
{
if (context->isIgnoringErrors())
{
(yyval) = static_cast<YYSTYPE>(0);
}
else
{
std::ostringstream stream;
stream << (yyvsp[-2]) << " / " << (yyvsp[0]);
std::string text = stream.str();
context->diagnostics->report(pp::Diagnostics::PP_DIVISION_BY_ZERO,
context->token->location,
text.c_str());
YYABORT;
}
}
else
{
if ((yyvsp[0]) == 0) {
std::ostringstream stream;
stream << (yyvsp[-2]) << " / " << (yyvsp[0]);
std::string text = stream.str();
context->diagnostics->report(pp::Diagnostics::PP_DIVISION_BY_ZERO,
context->token->location,
text.c_str());
YYABORT;
} else {
(yyval) = (yyvsp[-2]) / (yyvsp[0]);
}
}
break;
case 24:
case 21:
{
(yyval) = (yyvsp[-2]) * (yyvsp[0]);
......@@ -1581,7 +1491,7 @@ yyreduce:
break;
case 25:
case 22:
{
(yyval) = ! (yyvsp[0]);
......@@ -1589,7 +1499,7 @@ yyreduce:
break;
case 26:
case 23:
{
(yyval) = ~ (yyvsp[0]);
......@@ -1597,7 +1507,7 @@ yyreduce:
break;
case 27:
case 24:
{
(yyval) = - (yyvsp[0]);
......@@ -1605,7 +1515,7 @@ yyreduce:
break;
case 28:
case 25:
{
(yyval) = + (yyvsp[0]);
......@@ -1613,7 +1523,7 @@ yyreduce:
break;
case 29:
case 26:
{
(yyval) = (yyvsp[-1]);
......@@ -1871,15 +1781,6 @@ int yylex(YYSTYPE *lvalp, Context *context)
type = TOK_CONST_INT;
break;
}
case pp::Token::IDENTIFIER:
if (!context->isIgnoringErrors())
{
context->diagnostics->report(pp::Diagnostics::PP_CONDITIONAL_UNEXPECTED_TOKEN,
token->location, token->text);
}
*lvalp = static_cast<YYSTYPE>(-1);
type = TOK_IDENTIFIER;
break;
case pp::Token::OP_OR:
type = TOK_OP_OR;
break;
......@@ -1954,7 +1855,6 @@ bool ExpressionParser::parse(Token *token, int *result)
context.lexer = mLexer;
context.token = token;
context.result = result;
context.ignoreErrors = 0;
int ret = yyparse(&context);
switch (ret)
{
......
......@@ -64,13 +64,6 @@ struct Context
pp::Lexer* lexer;
pp::Token* token;
int* result;
void startIgnoreErrors() { ++ignoreErrors; }
void endIgnoreErrors() { --ignoreErrors; }
bool isIgnoringErrors() { return ignoreErrors > 0; }
int ignoreErrors;
};
} // namespace
%}
......@@ -86,7 +79,6 @@ static void yyerror(Context* context, const char* reason);
%}
%token TOK_CONST_INT
%token TOK_IDENTIFIER
%left TOK_OP_OR
%left TOK_OP_AND
%left '|'
......@@ -104,62 +96,17 @@ static void yyerror(Context* context, const char* reason);
input
: expression {
*(context->result) = static_cast<int>($1);
YYACCEPT;
}
;
expression
: TOK_CONST_INT
| TOK_IDENTIFIER {
if (!context->isIgnoringErrors())
{
YYABORT;
}
| expression TOK_OP_OR expression {
$$ = $1 || $3;
}
| expression TOK_OP_OR {
if ($1 != 0)
{
// Ignore errors in the short-circuited part of the expression.
// ESSL3.00 section 3.4:
// If an operand is not evaluated, the presence of undefined identifiers
// in the operand will not cause an error.
// Unevaluated division by zero should not cause an error either.
context->startIgnoreErrors();
}
} expression {
if ($1 != 0)
{
context->endIgnoreErrors();
// Make sure that short-circuited version of || works consistently
// with the normal version even for values other than 0 and 1.
$$ = $1 || 0;
}
else
{
$$ = $1 || $4;
}
}
| expression TOK_OP_AND {
if ($1 == 0)
{
// Ignore errors in the short-circuited part of the expression.
// ESSL3.00 section 3.4:
// If an operand is not evaluated, the presence of undefined identifiers
// in the operand will not cause an error.
// Unevaluated division by zero should not cause an error either.
context->startIgnoreErrors();
}
} expression {
if ($1 == 0)
{
context->endIgnoreErrors();
// Make sure that short-circuited version of && works consistently
// with the normal version even for values other than 0 and 1.
$$ = $1 && 0;
}
else
{
$$ = $1 && $4;
}
| expression TOK_OP_AND expression {
$$ = $1 && $3;
}
| expression '|' expression {
$$ = $1 | $3;
......@@ -201,48 +148,28 @@ expression
$$ = $1 + $3;
}
| expression '%' expression {
if ($3 == 0)
{
if (context->isIgnoringErrors())
{
$$ = static_cast<YYSTYPE>(0);
}
else
{
std::ostringstream stream;
stream << $1 << " % " << $3;
std::string text = stream.str();
context->diagnostics->report(pp::Diagnostics::PP_DIVISION_BY_ZERO,
context->token->location,
text.c_str());
YYABORT;
}
}
else
{
if ($3 == 0) {
std::ostringstream stream;
stream << $1 << " % " << $3;
std::string text = stream.str();
context->diagnostics->report(pp::Diagnostics::PP_DIVISION_BY_ZERO,
context->token->location,
text.c_str());
YYABORT;
} else {
$$ = $1 % $3;
}
}
| expression '/' expression {
if ($3 == 0)
{
if (context->isIgnoringErrors())
{
$$ = static_cast<YYSTYPE>(0);
}
else
{
std::ostringstream stream;
stream << $1 << " / " << $3;
std::string text = stream.str();
context->diagnostics->report(pp::Diagnostics::PP_DIVISION_BY_ZERO,
context->token->location,
text.c_str());
YYABORT;
}
}
else
{
if ($3 == 0) {
std::ostringstream stream;
stream << $1 << " / " << $3;
std::string text = stream.str();
context->diagnostics->report(pp::Diagnostics::PP_DIVISION_BY_ZERO,
context->token->location,
text.c_str());
YYABORT;
} else {
$$ = $1 / $3;
}
}
......@@ -286,15 +213,6 @@ int yylex(YYSTYPE *lvalp, Context *context)
type = TOK_CONST_INT;
break;
}
case pp::Token::IDENTIFIER:
if (!context->isIgnoringErrors())
{
context->diagnostics->report(pp::Diagnostics::PP_CONDITIONAL_UNEXPECTED_TOKEN,
token->location, token->text);
}
*lvalp = static_cast<YYSTYPE>(-1);
type = TOK_IDENTIFIER;
break;
case pp::Token::OP_OR:
type = TOK_OP_OR;
break;
......@@ -369,7 +287,6 @@ bool ExpressionParser::parse(Token *token, int *result)
context.lexer = mLexer;
context.token = token;
context.result = result;
context.ignoreErrors = 0;
int ret = yyparse(&context);
switch (ret)
{
......
......@@ -697,6 +697,10 @@ TEST_F(IfTest, UndefinedMacro)
ASSERT_TRUE(mPreprocessor.init(1, &str, 0));
EXPECT_CALL(mDiagnostics,
print(pp::Diagnostics::PP_INVALID_EXPRESSION,
pp::SourceLocation(0, 1),
"syntax error"));
EXPECT_CALL(mDiagnostics,
print(pp::Diagnostics::PP_CONDITIONAL_UNEXPECTED_TOKEN,
pp::SourceLocation(0, 1),
"UNDEFINED"));
......@@ -829,65 +833,3 @@ TEST_F(IfTest, UnterminatedIfdef)
mPreprocessor.lex(&token);
}
// The preprocessor only allows one expression to follow an #if directive.
// Supplying two integer expressions should be an error.
TEST_F(IfTest, ExtraIntExpression)
{
const char *str =
"#if 1 1\n"
"#endif\n";
ASSERT_TRUE(mPreprocessor.init(1, &str, 0));
EXPECT_CALL(mDiagnostics, print(pp::Diagnostics::PP_INVALID_EXPRESSION,
pp::SourceLocation(0, 1), "syntax error"));
pp::Token token;
mPreprocessor.lex(&token);
}
// The preprocessor only allows one expression to follow an #if directive.
// Supplying two expressions where one uses a preprocessor define should be an error.
TEST_F(IfTest, ExtraIdentifierExpression)
{
const char *str =
"#define one 1\n"
"#if 1 one\n"
"#endif\n";
ASSERT_TRUE(mPreprocessor.init(1, &str, 0));
EXPECT_CALL(mDiagnostics, print(pp::Diagnostics::PP_INVALID_EXPRESSION,
pp::SourceLocation(0, 2), "syntax error"));
pp::Token token;
mPreprocessor.lex(&token);
}
// Divide by zero that's not evaluated because of short-circuiting should not cause an error.
TEST_F(IfTest, ShortCircuitedDivideByZero)
{
const char *str =
"#if 1 || (2 / 0)\n"
"pass\n"
"#endif\n";
const char *expected =
"\n"
"pass\n"
"\n";
preprocess(str, expected);
}
// Undefined identifier that's not evaluated because of short-circuiting should not cause an error.
TEST_F(IfTest, ShortCircuitedUndefined)
{
const char *str =
"#if 1 || UNDEFINED\n"
"pass\n"
"#endif\n";
const char *expected =
"\n"
"pass\n"
"\n";
preprocess(str, expected);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment