Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(195)

Side by Side Diff: src/preparser.cc

Issue 6529032: Merge 6168:6800 from bleeding_edge to experimental/gc branch. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/gc/
Patch Set: Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/preparser.h ('k') | src/preparser-api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1
1 // Copyright 2010 the V8 project authors. All rights reserved. 2 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 3 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 4 // modification, are permitted provided that the following conditions are
4 // met: 5 // met:
5 // 6 //
6 // * Redistributions of source code must retain the above copyright 7 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 8 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 9 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 10 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 11 // disclaimer in the documentation and/or other materials provided
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 case i::Token::EOS: 76 case i::Token::EOS:
76 return ReportMessageAt(source_location.beg_pos, source_location.end_pos, 77 return ReportMessageAt(source_location.beg_pos, source_location.end_pos,
77 "unexpected_eos", NULL); 78 "unexpected_eos", NULL);
78 case i::Token::NUMBER: 79 case i::Token::NUMBER:
79 return ReportMessageAt(source_location.beg_pos, source_location.end_pos, 80 return ReportMessageAt(source_location.beg_pos, source_location.end_pos,
80 "unexpected_token_number", NULL); 81 "unexpected_token_number", NULL);
81 case i::Token::STRING: 82 case i::Token::STRING:
82 return ReportMessageAt(source_location.beg_pos, source_location.end_pos, 83 return ReportMessageAt(source_location.beg_pos, source_location.end_pos,
83 "unexpected_token_string", NULL); 84 "unexpected_token_string", NULL);
84 case i::Token::IDENTIFIER: 85 case i::Token::IDENTIFIER:
86 case i::Token::FUTURE_RESERVED_WORD:
85 return ReportMessageAt(source_location.beg_pos, source_location.end_pos, 87 return ReportMessageAt(source_location.beg_pos, source_location.end_pos,
86 "unexpected_token_identifier", NULL); 88 "unexpected_token_identifier", NULL);
87 default: 89 default:
88 const char* name = i::Token::String(token); 90 const char* name = i::Token::String(token);
89 ReportMessageAt(source_location.beg_pos, source_location.end_pos, 91 ReportMessageAt(source_location.beg_pos, source_location.end_pos,
90 "unexpected_token", name); 92 "unexpected_token", name);
91 } 93 }
92 } 94 }
93 95
94 96
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 PreParser::Expression PreParser::ParseMemberWithNewPrefixesExpression( 784 PreParser::Expression PreParser::ParseMemberWithNewPrefixesExpression(
783 unsigned new_count, bool* ok) { 785 unsigned new_count, bool* ok) {
784 // MemberExpression :: 786 // MemberExpression ::
785 // (PrimaryExpression | FunctionLiteral) 787 // (PrimaryExpression | FunctionLiteral)
786 // ('[' Expression ']' | '.' Identifier | Arguments)* 788 // ('[' Expression ']' | '.' Identifier | Arguments)*
787 789
788 // Parse the initial primary or function expression. 790 // Parse the initial primary or function expression.
789 Expression result = kUnknownExpression; 791 Expression result = kUnknownExpression;
790 if (peek() == i::Token::FUNCTION) { 792 if (peek() == i::Token::FUNCTION) {
791 Consume(i::Token::FUNCTION); 793 Consume(i::Token::FUNCTION);
792 if (peek() == i::Token::IDENTIFIER) { 794 if (peek_any_identifier()) {
793 ParseIdentifier(CHECK_OK); 795 ParseIdentifier(CHECK_OK);
794 } 796 }
795 result = ParseFunctionLiteral(CHECK_OK); 797 result = ParseFunctionLiteral(CHECK_OK);
796 } else { 798 } else {
797 result = ParsePrimaryExpression(CHECK_OK); 799 result = ParsePrimaryExpression(CHECK_OK);
798 } 800 }
799 801
800 while (true) { 802 while (true) {
801 switch (peek()) { 803 switch (peek()) {
802 case i::Token::LBRACK: { 804 case i::Token::LBRACK: {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 // '(' Expression ')' 852 // '(' Expression ')'
851 853
852 Expression result = kUnknownExpression; 854 Expression result = kUnknownExpression;
853 switch (peek()) { 855 switch (peek()) {
854 case i::Token::THIS: { 856 case i::Token::THIS: {
855 Next(); 857 Next();
856 result = kThisExpression; 858 result = kThisExpression;
857 break; 859 break;
858 } 860 }
859 861
860 case i::Token::IDENTIFIER: { 862 case i::Token::IDENTIFIER:
863 case i::Token::FUTURE_RESERVED_WORD: {
861 ParseIdentifier(CHECK_OK); 864 ParseIdentifier(CHECK_OK);
862 result = kIdentifierExpression; 865 result = kIdentifierExpression;
863 break; 866 break;
864 } 867 }
865 868
866 case i::Token::NULL_LITERAL: 869 case i::Token::NULL_LITERAL:
867 case i::Token::TRUE_LITERAL: 870 case i::Token::TRUE_LITERAL:
868 case i::Token::FALSE_LITERAL: 871 case i::Token::FALSE_LITERAL:
869 case i::Token::NUMBER: { 872 case i::Token::NUMBER: {
870 Next(); 873 Next();
(...skipping 16 matching lines...) Expand all
887 case i::Token::LBRACK: 890 case i::Token::LBRACK:
888 result = ParseArrayLiteral(CHECK_OK); 891 result = ParseArrayLiteral(CHECK_OK);
889 break; 892 break;
890 893
891 case i::Token::LBRACE: 894 case i::Token::LBRACE:
892 result = ParseObjectLiteral(CHECK_OK); 895 result = ParseObjectLiteral(CHECK_OK);
893 break; 896 break;
894 897
895 case i::Token::LPAREN: 898 case i::Token::LPAREN:
896 Consume(i::Token::LPAREN); 899 Consume(i::Token::LPAREN);
900 parenthesized_function_ = (peek() == i::Token::FUNCTION);
897 result = ParseExpression(true, CHECK_OK); 901 result = ParseExpression(true, CHECK_OK);
898 Expect(i::Token::RPAREN, CHECK_OK); 902 Expect(i::Token::RPAREN, CHECK_OK);
899 if (result == kIdentifierExpression) result = kUnknownExpression; 903 if (result == kIdentifierExpression) result = kUnknownExpression;
900 break; 904 break;
901 905
902 case i::Token::MOD: 906 case i::Token::MOD:
903 result = ParseV8Intrinsic(CHECK_OK); 907 result = ParseV8Intrinsic(CHECK_OK);
904 break; 908 break;
905 909
906 default: { 910 default: {
(...skipping 30 matching lines...) Expand all
937 // ObjectLiteral :: 941 // ObjectLiteral ::
938 // '{' ( 942 // '{' (
939 // ((IdentifierName | String | Number) ':' AssignmentExpression) 943 // ((IdentifierName | String | Number) ':' AssignmentExpression)
940 // | (('get' | 'set') (IdentifierName | String | Number) FunctionLiteral) 944 // | (('get' | 'set') (IdentifierName | String | Number) FunctionLiteral)
941 // )*[','] '}' 945 // )*[','] '}'
942 946
943 Expect(i::Token::LBRACE, CHECK_OK); 947 Expect(i::Token::LBRACE, CHECK_OK);
944 while (peek() != i::Token::RBRACE) { 948 while (peek() != i::Token::RBRACE) {
945 i::Token::Value next = peek(); 949 i::Token::Value next = peek();
946 switch (next) { 950 switch (next) {
947 case i::Token::IDENTIFIER: { 951 case i::Token::IDENTIFIER:
952 case i::Token::FUTURE_RESERVED_WORD: {
948 bool is_getter = false; 953 bool is_getter = false;
949 bool is_setter = false; 954 bool is_setter = false;
950 ParseIdentifierOrGetOrSet(&is_getter, &is_setter, CHECK_OK); 955 ParseIdentifierOrGetOrSet(&is_getter, &is_setter, CHECK_OK);
951 if ((is_getter || is_setter) && peek() != i::Token::COLON) { 956 if ((is_getter || is_setter) && peek() != i::Token::COLON) {
952 i::Token::Value name = Next(); 957 i::Token::Value name = Next();
953 bool is_keyword = i::Token::IsKeyword(name); 958 bool is_keyword = i::Token::IsKeyword(name);
954 if (name != i::Token::IDENTIFIER && 959 if (name != i::Token::IDENTIFIER &&
960 name != i::Token::FUTURE_RESERVED_WORD &&
955 name != i::Token::NUMBER && 961 name != i::Token::NUMBER &&
956 name != i::Token::STRING && 962 name != i::Token::STRING &&
957 !is_keyword) { 963 !is_keyword) {
958 *ok = false; 964 *ok = false;
959 return kUnknownExpression; 965 return kUnknownExpression;
960 } 966 }
961 if (!is_keyword) { 967 if (!is_keyword) {
962 LogSymbol(); 968 LogSymbol();
963 } 969 }
964 ParseFunctionLiteral(CHECK_OK); 970 ParseFunctionLiteral(CHECK_OK);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 } 1070 }
1065 } 1071 }
1066 Expect(i::Token::RPAREN, CHECK_OK); 1072 Expect(i::Token::RPAREN, CHECK_OK);
1067 1073
1068 Expect(i::Token::LBRACE, CHECK_OK); 1074 Expect(i::Token::LBRACE, CHECK_OK);
1069 int function_block_pos = scanner_->location().beg_pos; 1075 int function_block_pos = scanner_->location().beg_pos;
1070 1076
1071 // Determine if the function will be lazily compiled. 1077 // Determine if the function will be lazily compiled.
1072 // Currently only happens to top-level functions. 1078 // Currently only happens to top-level functions.
1073 // Optimistically assume that all top-level functions are lazily compiled. 1079 // Optimistically assume that all top-level functions are lazily compiled.
1074 bool is_lazily_compiled = 1080 bool is_lazily_compiled = (outer_scope_type == kTopLevelScope &&
1075 (outer_scope_type == kTopLevelScope && !inside_with && allow_lazy_); 1081 !inside_with && allow_lazy_ &&
1082 !parenthesized_function_);
1083 parenthesized_function_ = false;
1076 1084
1077 if (is_lazily_compiled) { 1085 if (is_lazily_compiled) {
1078 log_->PauseRecording(); 1086 log_->PauseRecording();
1079 ParseSourceElements(i::Token::RBRACE, ok); 1087 ParseSourceElements(i::Token::RBRACE, ok);
1080 log_->ResumeRecording(); 1088 log_->ResumeRecording();
1081 if (!*ok) return kUnknownExpression; 1089 if (!*ok) return kUnknownExpression;
1082 1090
1083 Expect(i::Token::RBRACE, CHECK_OK); 1091 Expect(i::Token::RBRACE, CHECK_OK);
1084 1092
1085 // Position right after terminal '}'. 1093 // Position right after terminal '}'.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1140 } 1148 }
1141 1149
1142 1150
1143 PreParser::Expression PreParser::GetStringSymbol() { 1151 PreParser::Expression PreParser::GetStringSymbol() {
1144 LogSymbol(); 1152 LogSymbol();
1145 return kUnknownExpression; 1153 return kUnknownExpression;
1146 } 1154 }
1147 1155
1148 1156
1149 PreParser::Identifier PreParser::ParseIdentifier(bool* ok) { 1157 PreParser::Identifier PreParser::ParseIdentifier(bool* ok) {
1150 Expect(i::Token::IDENTIFIER, ok); 1158 if (!Check(i::Token::FUTURE_RESERVED_WORD)) {
1159 Expect(i::Token::IDENTIFIER, ok);
1160 }
1151 if (!*ok) return kUnknownIdentifier; 1161 if (!*ok) return kUnknownIdentifier;
1152 return GetIdentifierSymbol(); 1162 return GetIdentifierSymbol();
1153 } 1163 }
1154 1164
1155 1165
1156 PreParser::Identifier PreParser::ParseIdentifierName(bool* ok) { 1166 PreParser::Identifier PreParser::ParseIdentifierName(bool* ok) {
1157 i::Token::Value next = Next(); 1167 i::Token::Value next = Next();
1158 if (i::Token::IsKeyword(next)) { 1168 if (i::Token::IsKeyword(next)) {
1159 int pos = scanner_->location().beg_pos; 1169 int pos = scanner_->location().beg_pos;
1160 const char* keyword = i::Token::String(next); 1170 const char* keyword = i::Token::String(next);
1161 log_->LogAsciiSymbol(pos, i::Vector<const char>(keyword, 1171 log_->LogAsciiSymbol(pos, i::Vector<const char>(keyword,
1162 i::StrLength(keyword))); 1172 i::StrLength(keyword)));
1163 return kUnknownExpression; 1173 return kUnknownExpression;
1164 } 1174 }
1165 if (next == i::Token::IDENTIFIER) { 1175 if (next == i::Token::IDENTIFIER ||
1176 next == i::Token::FUTURE_RESERVED_WORD) {
1166 return GetIdentifierSymbol(); 1177 return GetIdentifierSymbol();
1167 } 1178 }
1168 *ok = false; 1179 *ok = false;
1169 return kUnknownIdentifier; 1180 return kUnknownIdentifier;
1170 } 1181 }
1171 1182
1172 1183
1173 // This function reads an identifier and determines whether or not it 1184 // This function reads an identifier and determines whether or not it
1174 // is 'get' or 'set'. The reason for not using ParseIdentifier and 1185 // is 'get' or 'set'.
1175 // checking on the output is that this involves heap allocation which
1176 // we can't do during preparsing.
1177 PreParser::Identifier PreParser::ParseIdentifierOrGetOrSet(bool* is_get, 1186 PreParser::Identifier PreParser::ParseIdentifierOrGetOrSet(bool* is_get,
1178 bool* is_set, 1187 bool* is_set,
1179 bool* ok) { 1188 bool* ok) {
1180 Expect(i::Token::IDENTIFIER, CHECK_OK); 1189 PreParser::Identifier result = ParseIdentifier(CHECK_OK);
1181 if (scanner_->is_literal_ascii() && scanner_->literal_length() == 3) { 1190 if (scanner_->is_literal_ascii() && scanner_->literal_length() == 3) {
1182 const char* token = scanner_->literal_ascii_string().start(); 1191 const char* token = scanner_->literal_ascii_string().start();
1183 *is_get = strncmp(token, "get", 3) == 0; 1192 *is_get = strncmp(token, "get", 3) == 0;
1184 *is_set = !*is_get && strncmp(token, "set", 3) == 0; 1193 *is_set = !*is_get && strncmp(token, "set", 3) == 0;
1185 } 1194 }
1186 return GetIdentifierSymbol(); 1195 return result;
1196 }
1197
1198 bool PreParser::peek_any_identifier() {
1199 i::Token::Value next = peek();
1200 return next == i::Token::IDENTIFIER ||
1201 next == i::Token::FUTURE_RESERVED_WORD;
1187 } 1202 }
1188 1203
1189 #undef CHECK_OK 1204 #undef CHECK_OK
1190 } } // v8::preparser 1205 } } // v8::preparser
OLDNEW
« no previous file with comments | « src/preparser.h ('k') | src/preparser-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698