Chromium Code Reviews| 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 891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 902 | 902 |
| 903 | 903 |
| 904 class ParserRecorder: public ParserLog { | 904 class ParserRecorder: public ParserLog { |
| 905 public: | 905 public: |
| 906 ParserRecorder(); | 906 ParserRecorder(); |
| 907 virtual FunctionEntry LogFunction(int start); | 907 virtual FunctionEntry LogFunction(int start); |
| 908 virtual void LogError() { } | 908 virtual void LogError() { } |
| 909 virtual void LogMessage(Scanner::Location loc, | 909 virtual void LogMessage(Scanner::Location loc, |
| 910 const char* message, | 910 const char* message, |
| 911 Vector<const char*> args); | 911 Vector<const char*> args); |
| 912 void WriteString(Vector<const char> str); | 912 Vector<unsigned> ExtractData() { |
| 913 static const char* ReadString(unsigned* start, int* chars); | 913 return store_.ToVector(); |
| 914 List<unsigned>* store() { return &store_; } | 914 } |
| 915 private: | 915 private: |
| 916 bool has_error_; | 916 bool has_error_; |
| 917 List<unsigned> store_; | 917 Collector<unsigned> store_; |
| 918 Vector<unsigned> preamble_; | |
| 919 | |
| 920 Collector<unsigned>* store() { return &store_; } | |
| 921 void WriteString(Vector<const char> str); | |
| 918 }; | 922 }; |
| 919 | 923 |
| 920 | 924 |
| 921 FunctionEntry ScriptDataImpl::GetFunctionEnd(int start) { | 925 FunctionEntry ScriptDataImpl::GetFunctionEnd(int start) { |
| 922 if (nth(last_entry_).start_pos() > start) { | 926 if (nth(last_entry_).start_pos() > start) { |
| 923 // If the last entry we looked up is higher than what we're | 927 // If the last entry we looked up is higher than what we're |
| 924 // looking for then it's useless and we reset it. | 928 // looking for then it's useless and we reset it. |
| 925 last_entry_ = 0; | 929 last_entry_ = 0; |
| 926 } | 930 } |
| 927 for (int i = last_entry_; i < EntryCount(); i++) { | 931 for (int i = last_entry_; i < EntryCount(); i++) { |
| 928 FunctionEntry entry = nth(i); | 932 FunctionEntry entry = nth(i); |
| 929 if (entry.start_pos() == start) { | 933 if (entry.start_pos() == start) { |
| 930 last_entry_ = i; | 934 last_entry_ = i; |
| 931 return entry; | 935 return entry; |
| 932 } | 936 } |
| 933 } | 937 } |
| 934 return FunctionEntry(); | 938 return FunctionEntry(); |
| 935 } | 939 } |
| 936 | 940 |
| 937 | 941 |
| 938 bool ScriptDataImpl::SanityCheck() { | 942 bool ScriptDataImpl::SanityCheck() { |
| 939 if (store_.length() < static_cast<int>(ScriptDataImpl::kHeaderSize)) | 943 if (store_.length() < static_cast<int>(ScriptDataImpl::kHeaderSize)) { |
| 940 return false; | 944 return false; |
| 941 if (magic() != ScriptDataImpl::kMagicNumber) | 945 } |
| 942 return false; | 946 if (magic() != ScriptDataImpl::kMagicNumber) return false; |
| 943 if (version() != ScriptDataImpl::kCurrentVersion) | 947 if (version() != ScriptDataImpl::kCurrentVersion) return false; |
| 944 return false; | |
| 945 return true; | 948 return true; |
| 946 } | 949 } |
| 947 | 950 |
| 948 | 951 |
| 949 int ScriptDataImpl::EntryCount() { | 952 int ScriptDataImpl::EntryCount() { |
| 950 return (store_.length() - kHeaderSize) / FunctionEntry::kSize; | 953 return (store_.length() - kHeaderSize) / FunctionEntry::kSize; |
| 951 } | 954 } |
| 952 | 955 |
| 953 | 956 |
| 954 FunctionEntry ScriptDataImpl::nth(int n) { | 957 FunctionEntry ScriptDataImpl::nth(int n) { |
| 955 int offset = kHeaderSize + n * FunctionEntry::kSize; | 958 int offset = kHeaderSize + n * FunctionEntry::kSize; |
| 956 return FunctionEntry(Vector<unsigned>(store_.start() + offset, | 959 return FunctionEntry(Vector<unsigned>(store_.start() + offset, |
| 957 FunctionEntry::kSize)); | 960 FunctionEntry::kSize)); |
| 958 } | 961 } |
| 959 | 962 |
| 960 | 963 |
| 961 ParserRecorder::ParserRecorder() | 964 ParserRecorder::ParserRecorder() |
| 962 : has_error_(false), store_(4) { | 965 : has_error_(false), store_(ScriptDataImpl::kHeaderSize) { |
|
Mads Ager (chromium)
2010/08/24 14:25:54
Four space indent.
| |
| 963 Vector<unsigned> preamble = store()->AddBlock(0, ScriptDataImpl::kHeaderSize); | 966 preamble_ = store()->AddBlock(ScriptDataImpl::kHeaderSize, 0); |
| 964 preamble[ScriptDataImpl::kMagicOffset] = ScriptDataImpl::kMagicNumber; | 967 preamble_[ScriptDataImpl::kMagicOffset] = ScriptDataImpl::kMagicNumber; |
| 965 preamble[ScriptDataImpl::kVersionOffset] = ScriptDataImpl::kCurrentVersion; | 968 preamble_[ScriptDataImpl::kVersionOffset] = ScriptDataImpl::kCurrentVersion; |
| 966 preamble[ScriptDataImpl::kHasErrorOffset] = false; | 969 preamble_[ScriptDataImpl::kHasErrorOffset] = false; |
| 967 } | 970 } |
| 968 | 971 |
| 969 | 972 |
| 970 void ParserRecorder::WriteString(Vector<const char> str) { | 973 void ParserRecorder::WriteString(Vector<const char> str) { |
| 971 store()->Add(str.length()); | 974 store()->Add(str.length()); |
| 972 for (int i = 0; i < str.length(); i++) | 975 for (int i = 0; i < str.length(); i++) { |
| 973 store()->Add(str[i]); | 976 store()->Add(str[i]); |
| 977 } | |
| 974 } | 978 } |
| 975 | 979 |
| 976 | 980 |
| 977 const char* ParserRecorder::ReadString(unsigned* start, int* chars) { | 981 const char* ScriptDataImpl::ReadString(unsigned* start, int* chars) { |
| 978 int length = start[0]; | 982 int length = start[0]; |
| 979 char* result = NewArray<char>(length + 1); | 983 char* result = NewArray<char>(length + 1); |
| 980 for (int i = 0; i < length; i++) | 984 for (int i = 0; i < length; i++) { |
| 981 result[i] = start[i + 1]; | 985 result[i] = start[i + 1]; |
| 986 } | |
| 982 result[length] = '\0'; | 987 result[length] = '\0'; |
| 983 if (chars != NULL) *chars = length; | 988 if (chars != NULL) *chars = length; |
| 984 return result; | 989 return result; |
| 985 } | 990 } |
| 986 | 991 |
| 987 | 992 |
| 988 void ParserRecorder::LogMessage(Scanner::Location loc, const char* message, | 993 void ParserRecorder::LogMessage(Scanner::Location loc, const char* message, |
| 989 Vector<const char*> args) { | 994 Vector<const char*> args) { |
| 990 if (has_error_) return; | 995 if (has_error_) return; |
| 991 store()->Rewind(ScriptDataImpl::kHeaderSize); | 996 store()->Reset(); |
| 992 store()->at(ScriptDataImpl::kHasErrorOffset) = true; | 997 preamble_ = store()->AddBlock(ScriptDataImpl::kHeaderSize, 0); |
| 998 preamble_[ScriptDataImpl::kMagicOffset] = ScriptDataImpl::kMagicNumber; | |
| 999 preamble_[ScriptDataImpl::kVersionOffset] = ScriptDataImpl::kCurrentVersion; | |
| 1000 preamble_[ScriptDataImpl::kHasErrorOffset] = true; | |
| 993 store()->Add(loc.beg_pos); | 1001 store()->Add(loc.beg_pos); |
| 994 store()->Add(loc.end_pos); | 1002 store()->Add(loc.end_pos); |
| 995 store()->Add(args.length()); | 1003 store()->Add(args.length()); |
| 996 WriteString(CStrVector(message)); | 1004 WriteString(CStrVector(message)); |
| 997 for (int i = 0; i < args.length(); i++) | 1005 for (int i = 0; i < args.length(); i++) { |
| 998 WriteString(CStrVector(args[i])); | 1006 WriteString(CStrVector(args[i])); |
| 1007 } | |
| 999 } | 1008 } |
| 1000 | 1009 |
| 1001 | 1010 |
| 1002 Scanner::Location ScriptDataImpl::MessageLocation() { | 1011 Scanner::Location ScriptDataImpl::MessageLocation() { |
| 1003 int beg_pos = Read(0); | 1012 int beg_pos = Read(0); |
| 1004 int end_pos = Read(1); | 1013 int end_pos = Read(1); |
| 1005 return Scanner::Location(beg_pos, end_pos); | 1014 return Scanner::Location(beg_pos, end_pos); |
| 1006 } | 1015 } |
| 1007 | 1016 |
| 1008 | 1017 |
| 1009 const char* ScriptDataImpl::BuildMessage() { | 1018 const char* ScriptDataImpl::BuildMessage() { |
| 1010 unsigned* start = ReadAddress(3); | 1019 unsigned* start = ReadAddress(3); |
| 1011 return ParserRecorder::ReadString(start, NULL); | 1020 return ReadString(start, NULL); |
| 1012 } | 1021 } |
| 1013 | 1022 |
| 1014 | 1023 |
| 1015 Vector<const char*> ScriptDataImpl::BuildArgs() { | 1024 Vector<const char*> ScriptDataImpl::BuildArgs() { |
| 1016 int arg_count = Read(2); | 1025 int arg_count = Read(2); |
| 1017 const char** array = NewArray<const char*>(arg_count); | 1026 const char** array = NewArray<const char*>(arg_count); |
| 1018 int pos = ScriptDataImpl::kHeaderSize + Read(3); | 1027 int pos = ScriptDataImpl::kHeaderSize + Read(3); |
| 1019 for (int i = 0; i < arg_count; i++) { | 1028 for (int i = 0; i < arg_count; i++) { |
| 1020 int count = 0; | 1029 int count = 0; |
| 1021 array[i] = ParserRecorder::ReadString(ReadAddress(pos), &count); | 1030 array[i] = ReadString(ReadAddress(pos), &count); |
| 1022 pos += count + 1; | 1031 pos += count + 1; |
| 1023 } | 1032 } |
| 1024 return Vector<const char*>(array, arg_count); | 1033 return Vector<const char*>(array, arg_count); |
| 1025 } | 1034 } |
| 1026 | 1035 |
| 1027 | 1036 |
| 1028 unsigned ScriptDataImpl::Read(int position) { | 1037 unsigned ScriptDataImpl::Read(int position) { |
| 1029 return store_[ScriptDataImpl::kHeaderSize + position]; | 1038 return store_[ScriptDataImpl::kHeaderSize + position]; |
| 1030 } | 1039 } |
| 1031 | 1040 |
| 1032 | 1041 |
| 1033 unsigned* ScriptDataImpl::ReadAddress(int position) { | 1042 unsigned* ScriptDataImpl::ReadAddress(int position) { |
| 1034 return &store_[ScriptDataImpl::kHeaderSize + position]; | 1043 return &store_[ScriptDataImpl::kHeaderSize + position]; |
| 1035 } | 1044 } |
| 1036 | 1045 |
| 1037 | 1046 |
| 1038 FunctionEntry ParserRecorder::LogFunction(int start) { | 1047 FunctionEntry ParserRecorder::LogFunction(int start) { |
| 1039 if (has_error_) return FunctionEntry(); | 1048 if (has_error_) return FunctionEntry(); |
| 1040 FunctionEntry result(store()->AddBlock(0, FunctionEntry::kSize)); | 1049 FunctionEntry result(store()->AddBlock(FunctionEntry::kSize, 0)); |
| 1041 result.set_start_pos(start); | 1050 result.set_start_pos(start); |
| 1042 return result; | 1051 return result; |
| 1043 } | 1052 } |
| 1044 | 1053 |
| 1045 | 1054 |
| 1046 class AstBuildingParser : public Parser { | 1055 class AstBuildingParser : public Parser { |
| 1047 public: | 1056 public: |
| 1048 AstBuildingParser(Handle<Script> script, bool allow_natives_syntax, | 1057 AstBuildingParser(Handle<Script> script, bool allow_natives_syntax, |
| 1049 v8::Extension* extension, ScriptDataImpl* pre_data) | 1058 v8::Extension* extension, ScriptDataImpl* pre_data) |
| 1050 : Parser(script, allow_natives_syntax, extension, PARSE, | 1059 : Parser(script, allow_natives_syntax, extension, PARSE, |
| (...skipping 4175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5226 ScriptDataImpl* PreParse(Handle<String> source, | 5235 ScriptDataImpl* PreParse(Handle<String> source, |
| 5227 unibrow::CharacterStream* stream, | 5236 unibrow::CharacterStream* stream, |
| 5228 v8::Extension* extension) { | 5237 v8::Extension* extension) { |
| 5229 Handle<Script> no_script; | 5238 Handle<Script> no_script; |
| 5230 bool allow_natives_syntax = | 5239 bool allow_natives_syntax = |
| 5231 always_allow_natives_syntax || | 5240 always_allow_natives_syntax || |
| 5232 FLAG_allow_natives_syntax || | 5241 FLAG_allow_natives_syntax || |
| 5233 Bootstrapper::IsActive(); | 5242 Bootstrapper::IsActive(); |
| 5234 PreParser parser(no_script, allow_natives_syntax, extension); | 5243 PreParser parser(no_script, allow_natives_syntax, extension); |
| 5235 if (!parser.PreParseProgram(source, stream)) return NULL; | 5244 if (!parser.PreParseProgram(source, stream)) return NULL; |
| 5236 // The list owns the backing store so we need to clone the vector. | 5245 // Extract the accumulated data from the recorder as a single |
| 5237 // That way, the result will be exactly the right size rather than | 5246 // contiguous vector that we are responsible for disposing. |
| 5238 // the expected 50% too large. | 5247 Vector<unsigned> store = parser.recorder()->ExtractData(); |
| 5239 Vector<unsigned> store = parser.recorder()->store()->ToVector().Clone(); | |
| 5240 return new ScriptDataImpl(store); | 5248 return new ScriptDataImpl(store); |
| 5241 } | 5249 } |
| 5242 | 5250 |
| 5243 | 5251 |
| 5244 bool ParseRegExp(FlatStringReader* input, | 5252 bool ParseRegExp(FlatStringReader* input, |
| 5245 bool multiline, | 5253 bool multiline, |
| 5246 RegExpCompileData* result) { | 5254 RegExpCompileData* result) { |
| 5247 ASSERT(result != NULL); | 5255 ASSERT(result != NULL); |
| 5248 RegExpParser parser(input, &result->error, multiline); | 5256 RegExpParser parser(input, &result->error, multiline); |
| 5249 RegExpTree* tree = parser.ParsePattern(); | 5257 RegExpTree* tree = parser.ParsePattern(); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5312 parser.ParseLazy(script_source, name, | 5320 parser.ParseLazy(script_source, name, |
| 5313 start_position, end_position, is_expression); | 5321 start_position, end_position, is_expression); |
| 5314 return result; | 5322 return result; |
| 5315 } | 5323 } |
| 5316 | 5324 |
| 5317 | 5325 |
| 5318 #undef NEW | 5326 #undef NEW |
| 5319 | 5327 |
| 5320 | 5328 |
| 5321 } } // namespace v8::internal | 5329 } } // namespace v8::internal |
| OLD | NEW |