| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 // is constructed based on the resources available at compile-time. | 42 // is constructed based on the resources available at compile-time. |
| 43 class CompilationInfo BASE_EMBEDDED { | 43 class CompilationInfo BASE_EMBEDDED { |
| 44 public: | 44 public: |
| 45 explicit CompilationInfo(Handle<Script> script); | 45 explicit CompilationInfo(Handle<Script> script); |
| 46 explicit CompilationInfo(Handle<SharedFunctionInfo> shared_info); | 46 explicit CompilationInfo(Handle<SharedFunctionInfo> shared_info); |
| 47 explicit CompilationInfo(Handle<JSFunction> closure); | 47 explicit CompilationInfo(Handle<JSFunction> closure); |
| 48 | 48 |
| 49 bool is_lazy() const { return (flags_ & IsLazy::mask()) != 0; } | 49 bool is_lazy() const { return (flags_ & IsLazy::mask()) != 0; } |
| 50 bool is_eval() const { return (flags_ & IsEval::mask()) != 0; } | 50 bool is_eval() const { return (flags_ & IsEval::mask()) != 0; } |
| 51 bool is_global() const { return (flags_ & IsGlobal::mask()) != 0; } | 51 bool is_global() const { return (flags_ & IsGlobal::mask()) != 0; } |
| 52 bool is_json() const { return (flags_ & IsJson::mask()) != 0; } | |
| 53 bool is_in_loop() const { return (flags_ & IsInLoop::mask()) != 0; } | 52 bool is_in_loop() const { return (flags_ & IsInLoop::mask()) != 0; } |
| 54 FunctionLiteral* function() const { return function_; } | 53 FunctionLiteral* function() const { return function_; } |
| 55 Scope* scope() const { return scope_; } | 54 Scope* scope() const { return scope_; } |
| 56 Handle<Code> code() const { return code_; } | 55 Handle<Code> code() const { return code_; } |
| 57 Handle<JSFunction> closure() const { return closure_; } | 56 Handle<JSFunction> closure() const { return closure_; } |
| 58 Handle<SharedFunctionInfo> shared_info() const { return shared_info_; } | 57 Handle<SharedFunctionInfo> shared_info() const { return shared_info_; } |
| 59 Handle<Script> script() const { return script_; } | 58 Handle<Script> script() const { return script_; } |
| 60 v8::Extension* extension() const { return extension_; } | 59 v8::Extension* extension() const { return extension_; } |
| 61 ScriptDataImpl* pre_parse_data() const { return pre_parse_data_; } | 60 ScriptDataImpl* pre_parse_data() const { return pre_parse_data_; } |
| 62 Handle<Context> calling_context() const { return calling_context_; } | 61 Handle<Context> calling_context() const { return calling_context_; } |
| 63 | 62 |
| 64 void MarkAsEval() { | 63 void MarkAsEval() { |
| 65 ASSERT(!is_lazy()); | 64 ASSERT(!is_lazy()); |
| 66 flags_ |= IsEval::encode(true); | 65 flags_ |= IsEval::encode(true); |
| 67 } | 66 } |
| 68 void MarkAsGlobal() { | 67 void MarkAsGlobal() { |
| 69 ASSERT(!is_lazy()); | 68 ASSERT(!is_lazy()); |
| 70 flags_ |= IsGlobal::encode(true); | 69 flags_ |= IsGlobal::encode(true); |
| 71 } | 70 } |
| 72 void MarkAsJson() { | |
| 73 ASSERT(!is_lazy()); | |
| 74 flags_ |= IsJson::encode(true); | |
| 75 } | |
| 76 void MarkAsInLoop() { | 71 void MarkAsInLoop() { |
| 77 ASSERT(is_lazy()); | 72 ASSERT(is_lazy()); |
| 78 flags_ |= IsInLoop::encode(true); | 73 flags_ |= IsInLoop::encode(true); |
| 79 } | 74 } |
| 80 void SetFunction(FunctionLiteral* literal) { | 75 void SetFunction(FunctionLiteral* literal) { |
| 81 ASSERT(function_ == NULL); | 76 ASSERT(function_ == NULL); |
| 82 function_ = literal; | 77 function_ = literal; |
| 83 } | 78 } |
| 84 void SetScope(Scope* scope) { | 79 void SetScope(Scope* scope) { |
| 85 ASSERT(scope_ == NULL); | 80 ASSERT(scope_ == NULL); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 101 | 96 |
| 102 private: | 97 private: |
| 103 // Flags using template class BitField<type, start, length>. All are | 98 // Flags using template class BitField<type, start, length>. All are |
| 104 // false by default. | 99 // false by default. |
| 105 // | 100 // |
| 106 // Compilation is either eager or lazy. | 101 // Compilation is either eager or lazy. |
| 107 class IsLazy: public BitField<bool, 0, 1> {}; | 102 class IsLazy: public BitField<bool, 0, 1> {}; |
| 108 // Flags that can be set for eager compilation. | 103 // Flags that can be set for eager compilation. |
| 109 class IsEval: public BitField<bool, 1, 1> {}; | 104 class IsEval: public BitField<bool, 1, 1> {}; |
| 110 class IsGlobal: public BitField<bool, 2, 1> {}; | 105 class IsGlobal: public BitField<bool, 2, 1> {}; |
| 111 class IsJson: public BitField<bool, 3, 1> {}; | |
| 112 // Flags that can be set for lazy compilation. | 106 // Flags that can be set for lazy compilation. |
| 113 class IsInLoop: public BitField<bool, 4, 1> {}; | 107 class IsInLoop: public BitField<bool, 3, 1> {}; |
| 114 | 108 |
| 115 unsigned flags_; | 109 unsigned flags_; |
| 116 | 110 |
| 117 // Fields filled in by the compilation pipeline. | 111 // Fields filled in by the compilation pipeline. |
| 118 // AST filled in by the parser. | 112 // AST filled in by the parser. |
| 119 FunctionLiteral* function_; | 113 FunctionLiteral* function_; |
| 120 // The scope of the function literal as a convenience. Set to indidicate | 114 // The scope of the function literal as a convenience. Set to indicate |
| 121 // that scopes have been analyzed. | 115 // that scopes have been analyzed. |
| 122 Scope* scope_; | 116 Scope* scope_; |
| 123 // The compiled code. | 117 // The compiled code. |
| 124 Handle<Code> code_; | 118 Handle<Code> code_; |
| 125 | 119 |
| 126 // Possible initial inputs to the compilation process. | 120 // Possible initial inputs to the compilation process. |
| 127 Handle<JSFunction> closure_; | 121 Handle<JSFunction> closure_; |
| 128 Handle<SharedFunctionInfo> shared_info_; | 122 Handle<SharedFunctionInfo> shared_info_; |
| 129 Handle<Script> script_; | 123 Handle<Script> script_; |
| 130 | 124 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 146 // parameters which then can be executed. If the source code contains other | 140 // parameters which then can be executed. If the source code contains other |
| 147 // functions, they will be compiled and allocated as part of the compilation | 141 // functions, they will be compiled and allocated as part of the compilation |
| 148 // of the source code. | 142 // of the source code. |
| 149 | 143 |
| 150 // Please note this interface returns shared function infos. This means you | 144 // Please note this interface returns shared function infos. This means you |
| 151 // need to call Factory::NewFunctionFromSharedFunctionInfo before you have a | 145 // need to call Factory::NewFunctionFromSharedFunctionInfo before you have a |
| 152 // real function with a context. | 146 // real function with a context. |
| 153 | 147 |
| 154 class Compiler : public AllStatic { | 148 class Compiler : public AllStatic { |
| 155 public: | 149 public: |
| 156 enum ValidationState { DONT_VALIDATE_JSON, VALIDATE_JSON }; | |
| 157 | |
| 158 // All routines return a JSFunction. | 150 // All routines return a JSFunction. |
| 159 // If an error occurs an exception is raised and | 151 // If an error occurs an exception is raised and |
| 160 // the return handle contains NULL. | 152 // the return handle contains NULL. |
| 161 | 153 |
| 162 // Compile a String source within a context. | 154 // Compile a String source within a context. |
| 163 static Handle<SharedFunctionInfo> Compile(Handle<String> source, | 155 static Handle<SharedFunctionInfo> Compile(Handle<String> source, |
| 164 Handle<Object> script_name, | 156 Handle<Object> script_name, |
| 165 int line_offset, | 157 int line_offset, |
| 166 int column_offset, | 158 int column_offset, |
| 167 v8::Extension* extension, | 159 v8::Extension* extension, |
| 168 ScriptDataImpl* pre_data, | 160 ScriptDataImpl* pre_data, |
| 169 Handle<Object> script_data, | 161 Handle<Object> script_data, |
| 170 NativesFlag is_natives_code); | 162 NativesFlag is_natives_code); |
| 171 | 163 |
| 172 // Compile a String source within a context for Eval. | 164 // Compile a String source within a context for Eval. |
| 173 static Handle<SharedFunctionInfo> CompileEval(Handle<String> source, | 165 static Handle<SharedFunctionInfo> CompileEval(Handle<String> source, |
| 174 Handle<Context> context, | 166 Handle<Context> context, |
| 175 bool is_global, | 167 bool is_global); |
| 176 ValidationState validation); | |
| 177 | 168 |
| 178 // Compile from function info (used for lazy compilation). Returns true on | 169 // Compile from function info (used for lazy compilation). Returns true on |
| 179 // success and false if the compilation resulted in a stack overflow. | 170 // success and false if the compilation resulted in a stack overflow. |
| 180 static bool CompileLazy(CompilationInfo* info); | 171 static bool CompileLazy(CompilationInfo* info); |
| 181 | 172 |
| 182 // Compile a shared function info object (the function is possibly lazily | 173 // Compile a shared function info object (the function is possibly lazily |
| 183 // compiled). | 174 // compiled). |
| 184 static Handle<SharedFunctionInfo> BuildFunctionInfo(FunctionLiteral* node, | 175 static Handle<SharedFunctionInfo> BuildFunctionInfo(FunctionLiteral* node, |
| 185 Handle<Script> script); | 176 Handle<Script> script); |
| 186 | 177 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 213 FrameElement::ClearConstantList(); | 204 FrameElement::ClearConstantList(); |
| 214 Result::ClearConstantList(); | 205 Result::ClearConstantList(); |
| 215 } | 206 } |
| 216 } | 207 } |
| 217 }; | 208 }; |
| 218 | 209 |
| 219 | 210 |
| 220 } } // namespace v8::internal | 211 } } // namespace v8::internal |
| 221 | 212 |
| 222 #endif // V8_COMPILER_H_ | 213 #endif // V8_COMPILER_H_ |
| OLD | NEW |