| 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 939 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 950 Expect(i::Token::LBRACE, CHECK_OK); | 950 Expect(i::Token::LBRACE, CHECK_OK); |
| 951 while (peek() != i::Token::RBRACE) { | 951 while (peek() != i::Token::RBRACE) { |
| 952 i::Token::Value next = peek(); | 952 i::Token::Value next = peek(); |
| 953 switch (next) { | 953 switch (next) { |
| 954 case i::Token::IDENTIFIER: { | 954 case i::Token::IDENTIFIER: { |
| 955 bool is_getter = false; | 955 bool is_getter = false; |
| 956 bool is_setter = false; | 956 bool is_setter = false; |
| 957 ParseIdentifierOrGetOrSet(&is_getter, &is_setter, CHECK_OK); | 957 ParseIdentifierOrGetOrSet(&is_getter, &is_setter, CHECK_OK); |
| 958 if ((is_getter || is_setter) && peek() != i::Token::COLON) { | 958 if ((is_getter || is_setter) && peek() != i::Token::COLON) { |
| 959 i::Token::Value name = Next(); | 959 i::Token::Value name = Next(); |
| 960 bool is_keyword = i::Token::IsKeyword(name); |
| 960 if (name != i::Token::IDENTIFIER && | 961 if (name != i::Token::IDENTIFIER && |
| 961 name != i::Token::NUMBER && | 962 name != i::Token::NUMBER && |
| 962 name != i::Token::STRING && | 963 name != i::Token::STRING && |
| 963 !i::Token::IsKeyword(name)) { | 964 !is_keyword) { |
| 964 *ok = false; | 965 *ok = false; |
| 965 return kUnknownExpression; | 966 return kUnknownExpression; |
| 966 } | 967 } |
| 968 if (!is_keyword) { |
| 969 LogSymbol(); |
| 970 } |
| 967 ParseFunctionLiteral(CHECK_OK); | 971 ParseFunctionLiteral(CHECK_OK); |
| 968 if (peek() != i::Token::RBRACE) { | 972 if (peek() != i::Token::RBRACE) { |
| 969 Expect(i::Token::COMMA, CHECK_OK); | 973 Expect(i::Token::COMMA, CHECK_OK); |
| 970 } | 974 } |
| 971 continue; // restart the while | 975 continue; // restart the while |
| 972 } | 976 } |
| 973 break; | 977 break; |
| 974 } | 978 } |
| 975 case i::Token::STRING: | 979 case i::Token::STRING: |
| 976 Consume(next); | 980 Consume(next); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1120 } | 1124 } |
| 1121 if (scanner_->has_line_terminator_before_next() || | 1125 if (scanner_->has_line_terminator_before_next() || |
| 1122 tok == i::Token::RBRACE || | 1126 tok == i::Token::RBRACE || |
| 1123 tok == i::Token::EOS) { | 1127 tok == i::Token::EOS) { |
| 1124 return; | 1128 return; |
| 1125 } | 1129 } |
| 1126 Expect(i::Token::SEMICOLON, ok); | 1130 Expect(i::Token::SEMICOLON, ok); |
| 1127 } | 1131 } |
| 1128 | 1132 |
| 1129 | 1133 |
| 1134 void PreParser::LogSymbol() { |
| 1135 int identifier_pos = scanner_->location().beg_pos; |
| 1136 if (scanner_->is_literal_ascii()) { |
| 1137 log_->LogAsciiSymbol(identifier_pos, scanner_->literal_ascii_string()); |
| 1138 } else { |
| 1139 log_->LogUC16Symbol(identifier_pos, scanner_->literal_uc16_string()); |
| 1140 } |
| 1141 } |
| 1142 |
| 1143 |
| 1130 PreParser::Identifier PreParser::GetIdentifierSymbol() { | 1144 PreParser::Identifier PreParser::GetIdentifierSymbol() { |
| 1131 const char* literal_chars = scanner_->literal_string(); | 1145 LogSymbol(); |
| 1132 int literal_length = scanner_->literal_length(); | 1146 return kUnknownIdentifier; |
| 1133 int identifier_pos = scanner_->location().beg_pos; | |
| 1134 | |
| 1135 log_->LogSymbol(identifier_pos, literal_chars, literal_length); | |
| 1136 | |
| 1137 return kUnknownExpression; | |
| 1138 } | 1147 } |
| 1139 | 1148 |
| 1140 | 1149 |
| 1141 PreParser::Expression PreParser::GetStringSymbol() { | 1150 PreParser::Expression PreParser::GetStringSymbol() { |
| 1142 const char* literal_chars = scanner_->literal_string(); | 1151 LogSymbol(); |
| 1143 int literal_length = scanner_->literal_length(); | |
| 1144 | |
| 1145 int literal_position = scanner_->location().beg_pos; | |
| 1146 log_->LogSymbol(literal_position, literal_chars, literal_length); | |
| 1147 | |
| 1148 return kUnknownExpression; | 1152 return kUnknownExpression; |
| 1149 } | 1153 } |
| 1150 | 1154 |
| 1151 | 1155 |
| 1152 PreParser::Identifier PreParser::ParseIdentifier(bool* ok) { | 1156 PreParser::Identifier PreParser::ParseIdentifier(bool* ok) { |
| 1153 Expect(i::Token::IDENTIFIER, ok); | 1157 Expect(i::Token::IDENTIFIER, ok); |
| 1154 if (!*ok) return kUnknownIdentifier; | 1158 if (!*ok) return kUnknownIdentifier; |
| 1155 return GetIdentifierSymbol(); | 1159 return GetIdentifierSymbol(); |
| 1156 } | 1160 } |
| 1157 | 1161 |
| 1158 | 1162 |
| 1159 PreParser::Identifier PreParser::ParseIdentifierName(bool* ok) { | 1163 PreParser::Identifier PreParser::ParseIdentifierName(bool* ok) { |
| 1160 i::Token::Value next = Next(); | 1164 i::Token::Value next = Next(); |
| 1161 if (i::Token::IsKeyword(next)) { | 1165 if (i::Token::IsKeyword(next)) { |
| 1162 int pos = scanner_->location().beg_pos; | 1166 int pos = scanner_->location().beg_pos; |
| 1163 const char* keyword = i::Token::String(next); | 1167 const char* keyword = i::Token::String(next); |
| 1164 log_->LogSymbol(pos, keyword, i::StrLength(keyword)); | 1168 log_->LogAsciiSymbol(pos, i::Vector<const char>(keyword, |
| 1169 i::StrLength(keyword))); |
| 1165 return kUnknownExpression; | 1170 return kUnknownExpression; |
| 1166 } | 1171 } |
| 1167 if (next == i::Token::IDENTIFIER) { | 1172 if (next == i::Token::IDENTIFIER) { |
| 1168 return GetIdentifierSymbol(); | 1173 return GetIdentifierSymbol(); |
| 1169 } | 1174 } |
| 1170 *ok = false; | 1175 *ok = false; |
| 1171 return kUnknownIdentifier; | 1176 return kUnknownIdentifier; |
| 1172 } | 1177 } |
| 1173 | 1178 |
| 1174 | 1179 |
| 1175 // This function reads an identifier and determines whether or not it | 1180 // This function reads an identifier and determines whether or not it |
| 1176 // is 'get' or 'set'. The reason for not using ParseIdentifier and | 1181 // is 'get' or 'set'. The reason for not using ParseIdentifier and |
| 1177 // checking on the output is that this involves heap allocation which | 1182 // checking on the output is that this involves heap allocation which |
| 1178 // we can't do during preparsing. | 1183 // we can't do during preparsing. |
| 1179 PreParser::Identifier PreParser::ParseIdentifierOrGetOrSet(bool* is_get, | 1184 PreParser::Identifier PreParser::ParseIdentifierOrGetOrSet(bool* is_get, |
| 1180 bool* is_set, | 1185 bool* is_set, |
| 1181 bool* ok) { | 1186 bool* ok) { |
| 1182 Expect(i::Token::IDENTIFIER, CHECK_OK); | 1187 Expect(i::Token::IDENTIFIER, CHECK_OK); |
| 1183 if (scanner_->literal_length() == 3) { | 1188 if (scanner_->is_literal_ascii() && scanner_->literal_length() == 3) { |
| 1184 const char* token = scanner_->literal_string(); | 1189 const char* token = scanner_->literal_ascii_string().start(); |
| 1185 *is_get = strncmp(token, "get", 3) == 0; | 1190 *is_get = strncmp(token, "get", 3) == 0; |
| 1186 *is_set = !*is_get && strncmp(token, "set", 3) == 0; | 1191 *is_set = !*is_get && strncmp(token, "set", 3) == 0; |
| 1187 } | 1192 } |
| 1188 return GetIdentifierSymbol(); | 1193 return GetIdentifierSymbol(); |
| 1189 } | 1194 } |
| 1190 | 1195 |
| 1191 #undef CHECK_OK | 1196 #undef CHECK_OK |
| 1192 } } // v8::preparser | 1197 } } // v8::preparser |
| OLD | NEW |