OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 | 179 |
180 Expression ParseExpression(bool accept_IN, bool* ok); | 180 Expression ParseExpression(bool accept_IN, bool* ok); |
181 Expression ParseAssignmentExpression(bool accept_IN, bool* ok); | 181 Expression ParseAssignmentExpression(bool accept_IN, bool* ok); |
182 Expression ParseConditionalExpression(bool accept_IN, bool* ok); | 182 Expression ParseConditionalExpression(bool accept_IN, bool* ok); |
183 Expression ParseBinaryExpression(int prec, bool accept_IN, bool* ok); | 183 Expression ParseBinaryExpression(int prec, bool accept_IN, bool* ok); |
184 Expression ParseUnaryExpression(bool* ok); | 184 Expression ParseUnaryExpression(bool* ok); |
185 Expression ParsePostfixExpression(bool* ok); | 185 Expression ParsePostfixExpression(bool* ok); |
186 Expression ParseLeftHandSideExpression(bool* ok); | 186 Expression ParseLeftHandSideExpression(bool* ok); |
187 Expression ParseNewExpression(bool* ok); | 187 Expression ParseNewExpression(bool* ok); |
188 Expression ParseMemberExpression(bool* ok); | 188 Expression ParseMemberExpression(bool* ok); |
189 Expression ParseNewPrefix(int* new_count, bool* ok); | 189 Expression ParseMemberWithNewPrefixesExpression(unsigned new_count, bool* ok); |
190 Expression ParseMemberWithNewPrefixesExpression(int* new_count, bool* ok); | |
191 Expression ParsePrimaryExpression(bool* ok); | 190 Expression ParsePrimaryExpression(bool* ok); |
192 Expression ParseArrayLiteral(bool* ok); | 191 Expression ParseArrayLiteral(bool* ok); |
193 Expression ParseObjectLiteral(bool* ok); | 192 Expression ParseObjectLiteral(bool* ok); |
194 Expression ParseRegExpLiteral(bool seen_equal, bool* ok); | 193 Expression ParseRegExpLiteral(bool seen_equal, bool* ok); |
195 Expression ParseV8Intrinsic(bool* ok); | 194 Expression ParseV8Intrinsic(bool* ok); |
196 | 195 |
197 Arguments ParseArguments(bool* ok); | 196 Arguments ParseArguments(bool* ok); |
198 Expression ParseFunctionLiteral(bool* ok); | 197 Expression ParseFunctionLiteral(bool* ok); |
199 | 198 |
200 Identifier ParseIdentifier(bool* ok); | 199 Identifier ParseIdentifier(bool* ok); |
(...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
958 break; | 957 break; |
959 } | 958 } |
960 | 959 |
961 default: | 960 default: |
962 return result; | 961 return result; |
963 } | 962 } |
964 } | 963 } |
965 } | 964 } |
966 | 965 |
967 | 966 |
968 | |
969 template <typename Scanner, typename Log> | 967 template <typename Scanner, typename Log> |
970 Expression PreParser<Scanner, Log>::ParseNewPrefix(int* new_count, bool* ok) { | 968 Expression PreParser<Scanner, Log>::ParseNewExpression(bool* ok) { |
971 // NewExpression :: | 969 // NewExpression :: |
972 // ('new')+ MemberExpression | 970 // ('new')+ MemberExpression |
973 | 971 |
974 // The grammar for new expressions is pretty warped. The keyword | 972 // The grammar for new expressions is pretty warped. The keyword |
975 // 'new' can either be a part of the new expression (where it isn't | 973 // 'new' can either be a part of the new expression (where it isn't |
976 // followed by an argument list) or a part of the member expression, | 974 // followed by an argument list) or a part of the member expression, |
977 // where it must be followed by an argument list. To accommodate | 975 // where it must be followed by an argument list. To accommodate |
978 // this, we parse the 'new' keywords greedily and keep track of how | 976 // this, we parse the 'new' keywords greedily and keep track of how |
979 // many we have parsed. This information is then passed on to the | 977 // many we have parsed. This information is then passed on to the |
980 // member expression parser, which is only allowed to match argument | 978 // member expression parser, which is only allowed to match argument |
981 // lists as long as it has 'new' prefixes left | 979 // lists as long as it has 'new' prefixes left |
982 Expect(Token::NEW, CHECK_OK); | 980 unsigned new_count = 0; |
983 *new_count++; | 981 do { |
| 982 Consume(Token::NEW); |
| 983 new_count++; |
| 984 } while (peek() == Token::NEW); |
984 | 985 |
985 if (peek() == Token::NEW) { | 986 return ParseMemberWithNewPrefixesExpression(new_count, ok); |
986 ParseNewPrefix(new_count, CHECK_OK); | |
987 } else { | |
988 ParseMemberWithNewPrefixesExpression(new_count, CHECK_OK); | |
989 } | |
990 | |
991 if (*new_count > 0) { | |
992 *new_count--; | |
993 } | |
994 return kUnknownExpression; | |
995 } | |
996 | |
997 | |
998 template <typename Scanner, typename Log> | |
999 Expression PreParser<Scanner, Log>::ParseNewExpression(bool* ok) { | |
1000 int new_count = 0; | |
1001 return ParseNewPrefix(&new_count, ok); | |
1002 } | 987 } |
1003 | 988 |
1004 | 989 |
1005 template <typename Scanner, typename Log> | 990 template <typename Scanner, typename Log> |
1006 Expression PreParser<Scanner, Log>::ParseMemberExpression(bool* ok) { | 991 Expression PreParser<Scanner, Log>::ParseMemberExpression(bool* ok) { |
1007 return ParseMemberWithNewPrefixesExpression(NULL, ok); | 992 return ParseMemberWithNewPrefixesExpression(0, ok); |
1008 } | 993 } |
1009 | 994 |
1010 | 995 |
1011 template <typename Scanner, typename Log> | 996 template <typename Scanner, typename Log> |
1012 Expression PreParser<Scanner, Log>::ParseMemberWithNewPrefixesExpression( | 997 Expression PreParser<Scanner, Log>::ParseMemberWithNewPrefixesExpression( |
1013 int* new_count, bool* ok) { | 998 unsigned new_count, bool* ok) { |
1014 // MemberExpression :: | 999 // MemberExpression :: |
1015 // (PrimaryExpression | FunctionLiteral) | 1000 // (PrimaryExpression | FunctionLiteral) |
1016 // ('[' Expression ']' | '.' Identifier | Arguments)* | 1001 // ('[' Expression ']' | '.' Identifier | Arguments)* |
1017 | 1002 |
1018 // Parse the initial primary or function expression. | 1003 // Parse the initial primary or function expression. |
1019 Expression result = NULL; | 1004 Expression result = NULL; |
1020 if (peek() == Token::FUNCTION) { | 1005 if (peek() == Token::FUNCTION) { |
1021 Consume(Token::FUNCTION); | 1006 Consume(Token::FUNCTION); |
1022 if (peek() == Token::IDENTIFIER) { | 1007 if (peek() == Token::IDENTIFIER) { |
1023 ParseIdentifier(CHECK_OK); | 1008 ParseIdentifier(CHECK_OK); |
(...skipping 20 matching lines...) Expand all Loading... |
1044 Consume(Token::PERIOD); | 1029 Consume(Token::PERIOD); |
1045 ParseIdentifierName(CHECK_OK); | 1030 ParseIdentifierName(CHECK_OK); |
1046 if (result == kThisExpression) { | 1031 if (result == kThisExpression) { |
1047 result = kThisPropertyExpression; | 1032 result = kThisPropertyExpression; |
1048 } else { | 1033 } else { |
1049 result = kUnknownExpression; | 1034 result = kUnknownExpression; |
1050 } | 1035 } |
1051 break; | 1036 break; |
1052 } | 1037 } |
1053 case Token::LPAREN: { | 1038 case Token::LPAREN: { |
1054 if ((new_count == NULL) || *new_count == 0) return result; | 1039 if (new_count == 0) return result; |
1055 // Consume one of the new prefixes (already parsed). | 1040 // Consume one of the new prefixes (already parsed). |
1056 ParseArguments(CHECK_OK); | 1041 ParseArguments(CHECK_OK); |
1057 *new_count--; | 1042 new_count--; |
1058 result = kUnknownExpression; | 1043 result = kUnknownExpression; |
1059 break; | 1044 break; |
1060 } | 1045 } |
1061 default: | 1046 default: |
1062 return result; | 1047 return result; |
1063 } | 1048 } |
1064 } | 1049 } |
1065 } | 1050 } |
1066 | 1051 |
1067 | 1052 |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1419 *is_get = strncmp(token, "get", 3) == 0; | 1404 *is_get = strncmp(token, "get", 3) == 0; |
1420 *is_set = !*is_get && strncmp(token, "set", 3) == 0; | 1405 *is_set = !*is_get && strncmp(token, "set", 3) == 0; |
1421 } | 1406 } |
1422 return GetIdentifierSymbol(); | 1407 return GetIdentifierSymbol(); |
1423 } | 1408 } |
1424 | 1409 |
1425 #undef CHECK_OK | 1410 #undef CHECK_OK |
1426 } } } // v8::internal::preparser | 1411 } } } // v8::internal::preparser |
1427 | 1412 |
1428 #endif // V8_PREPARSER_H | 1413 #endif // V8_PREPARSER_H |
OLD | NEW |