OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/parsing/preparse-data.h" | 5 #include "src/parsing/preparse-data.h" |
6 #include "src/base/hashmap.h" | 6 #include "src/base/hashmap.h" |
7 #include "src/base/logging.h" | 7 #include "src/base/logging.h" |
8 #include "src/globals.h" | 8 #include "src/globals.h" |
9 #include "src/parsing/parser.h" | 9 #include "src/parsing/parser.h" |
10 #include "src/parsing/preparse-data-format.h" | 10 #include "src/parsing/preparse-data-format.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 function_store_.Add( | 26 function_store_.Add( |
27 FunctionEntry::EncodeFlags(language_mode, uses_super_property, calls_eval, | 27 FunctionEntry::EncodeFlags(language_mode, uses_super_property, calls_eval, |
28 has_duplicate_parameters)); | 28 has_duplicate_parameters)); |
29 } | 29 } |
30 | 30 |
31 ParserLogger::ParserLogger() { | 31 ParserLogger::ParserLogger() { |
32 preamble_[PreparseDataConstants::kMagicOffset] = | 32 preamble_[PreparseDataConstants::kMagicOffset] = |
33 PreparseDataConstants::kMagicNumber; | 33 PreparseDataConstants::kMagicNumber; |
34 preamble_[PreparseDataConstants::kVersionOffset] = | 34 preamble_[PreparseDataConstants::kVersionOffset] = |
35 PreparseDataConstants::kCurrentVersion; | 35 PreparseDataConstants::kCurrentVersion; |
36 preamble_[PreparseDataConstants::kHasErrorOffset] = false; | |
37 preamble_[PreparseDataConstants::kFunctionsSizeOffset] = 0; | 36 preamble_[PreparseDataConstants::kFunctionsSizeOffset] = 0; |
38 preamble_[PreparseDataConstants::kSizeOffset] = 0; | 37 preamble_[PreparseDataConstants::kSizeOffset] = 0; |
39 DCHECK_EQ(5, PreparseDataConstants::kHeaderSize); | 38 DCHECK_EQ(4, PreparseDataConstants::kHeaderSize); |
40 #ifdef DEBUG | 39 #ifdef DEBUG |
41 prev_start_ = -1; | 40 prev_start_ = -1; |
42 #endif | 41 #endif |
43 } | 42 } |
44 | 43 |
45 void ParserLogger::LogMessage(int start_pos, int end_pos, | |
46 MessageTemplate::Template message, | |
47 const char* arg_opt, ParseErrorType error_type) { | |
48 if (HasError()) return; | |
49 preamble_[PreparseDataConstants::kHasErrorOffset] = true; | |
50 function_store_.Reset(); | |
51 STATIC_ASSERT(PreparseDataConstants::kMessageStartPos == 0); | |
52 function_store_.Add(start_pos); | |
53 STATIC_ASSERT(PreparseDataConstants::kMessageEndPos == 1); | |
54 function_store_.Add(end_pos); | |
55 STATIC_ASSERT(PreparseDataConstants::kMessageArgCountPos == 2); | |
56 function_store_.Add((arg_opt == NULL) ? 0 : 1); | |
57 STATIC_ASSERT(PreparseDataConstants::kParseErrorTypePos == 3); | |
58 function_store_.Add(error_type); | |
59 STATIC_ASSERT(PreparseDataConstants::kMessageTemplatePos == 4); | |
60 function_store_.Add(static_cast<unsigned>(message)); | |
61 STATIC_ASSERT(PreparseDataConstants::kMessageArgPos == 5); | |
62 if (arg_opt != NULL) WriteString(CStrVector(arg_opt)); | |
63 } | |
64 | |
65 void ParserLogger::WriteString(Vector<const char> str) { | |
66 function_store_.Add(str.length()); | |
67 for (int i = 0; i < str.length(); i++) { | |
68 function_store_.Add(str[i]); | |
69 } | |
70 } | |
71 | |
72 ScriptData* ParserLogger::GetScriptData() { | 44 ScriptData* ParserLogger::GetScriptData() { |
73 int function_size = function_store_.size(); | 45 int function_size = function_store_.size(); |
74 int total_size = PreparseDataConstants::kHeaderSize + function_size; | 46 int total_size = PreparseDataConstants::kHeaderSize + function_size; |
75 unsigned* data = NewArray<unsigned>(total_size); | 47 unsigned* data = NewArray<unsigned>(total_size); |
76 preamble_[PreparseDataConstants::kFunctionsSizeOffset] = function_size; | 48 preamble_[PreparseDataConstants::kFunctionsSizeOffset] = function_size; |
77 MemCopy(data, preamble_, sizeof(preamble_)); | 49 MemCopy(data, preamble_, sizeof(preamble_)); |
78 if (function_size > 0) { | 50 if (function_size > 0) { |
79 function_store_.WriteTo(Vector<unsigned>( | 51 function_store_.WriteTo(Vector<unsigned>( |
80 data + PreparseDataConstants::kHeaderSize, function_size)); | 52 data + PreparseDataConstants::kHeaderSize, function_size)); |
81 } | 53 } |
82 DCHECK(IsAligned(reinterpret_cast<intptr_t>(data), kPointerAlignment)); | 54 DCHECK(IsAligned(reinterpret_cast<intptr_t>(data), kPointerAlignment)); |
83 ScriptData* result = new ScriptData(reinterpret_cast<byte*>(data), | 55 ScriptData* result = new ScriptData(reinterpret_cast<byte*>(data), |
84 total_size * sizeof(unsigned)); | 56 total_size * sizeof(unsigned)); |
85 result->AcquireDataOwnership(); | 57 result->AcquireDataOwnership(); |
86 return result; | 58 return result; |
87 } | 59 } |
88 | 60 |
89 | 61 |
90 } // namespace internal | 62 } // namespace internal |
91 } // namespace v8. | 63 } // namespace v8. |
OLD | NEW |