| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/compiler.h" | 5 #include "vm/compiler.h" |
| 6 | 6 |
| 7 #include "vm/assembler.h" | 7 #include "vm/assembler.h" |
| 8 | 8 |
| 9 #include "vm/ast_printer.h" | 9 #include "vm/ast_printer.h" |
| 10 #include "vm/block_scheduler.h" | 10 #include "vm/block_scheduler.h" |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 | 148 |
| 149 RawError* Compiler::CompileClass(const Class& cls) { | 149 RawError* Compiler::CompileClass(const Class& cls) { |
| 150 // If class is a top level class it is already parsed. | 150 // If class is a top level class it is already parsed. |
| 151 if (cls.IsTopLevel()) { | 151 if (cls.IsTopLevel()) { |
| 152 return Error::null(); | 152 return Error::null(); |
| 153 } | 153 } |
| 154 // If the class is already marked for parsing return immediately. | 154 // If the class is already marked for parsing return immediately. |
| 155 if (cls.is_marked_for_parsing()) { | 155 if (cls.is_marked_for_parsing()) { |
| 156 return Error::null(); | 156 return Error::null(); |
| 157 } | 157 } |
| 158 |
| 159 Isolate* isolate = Isolate::Current(); |
| 160 // We remember all the classes that are being compiled in these lists. This |
| 161 // also allows us to reset the marked_for_parsing state in case we see an |
| 162 // error. |
| 163 Class& parse_class = Class::Handle(); |
| 164 const GrowableObjectArray& parse_list = |
| 165 GrowableObjectArray::Handle(GrowableObjectArray::New(4)); |
| 166 const GrowableObjectArray& patch_list = |
| 167 GrowableObjectArray::Handle(GrowableObjectArray::New(4)); |
| 168 |
| 158 // Parse the class and all the interfaces it implements and super classes. | 169 // Parse the class and all the interfaces it implements and super classes. |
| 159 Isolate* isolate = Isolate::Current(); | |
| 160 StackZone zone(isolate); | 170 StackZone zone(isolate); |
| 161 LongJump* base = isolate->long_jump_base(); | 171 LongJump* base = isolate->long_jump_base(); |
| 162 LongJump jump; | 172 LongJump jump; |
| 163 isolate->set_long_jump_base(&jump); | 173 isolate->set_long_jump_base(&jump); |
| 164 if (setjmp(*jump.Set()) == 0) { | 174 if (setjmp(*jump.Set()) == 0) { |
| 165 if (FLAG_trace_compiler) { | 175 if (FLAG_trace_compiler) { |
| 166 OS::Print("Compiling Class %s '%s'\n", "", cls.ToCString()); | 176 OS::Print("Compiling Class %s '%s'\n", "", cls.ToCString()); |
| 167 } | 177 } |
| 168 | 178 |
| 169 Class& parse_class = Class::Handle(); | |
| 170 const GrowableObjectArray& parse_list = | |
| 171 GrowableObjectArray::Handle(GrowableObjectArray::New(4)); | |
| 172 const GrowableObjectArray& patch_list = | |
| 173 GrowableObjectArray::Handle(GrowableObjectArray::New(4)); | |
| 174 | |
| 175 // Add the primary class which needs to be parsed to the parse list. | 179 // Add the primary class which needs to be parsed to the parse list. |
| 176 // Mark the class as parsed so that we don't recursively add the same | 180 // Mark the class as parsed so that we don't recursively add the same |
| 177 // class back into the list. | 181 // class back into the list. |
| 178 parse_list.Add(cls); | 182 parse_list.Add(cls); |
| 179 cls.set_is_marked_for_parsing(); | 183 cls.set_is_marked_for_parsing(); |
| 180 | 184 |
| 181 // Add all super classes, interface classes and patch class if one | 185 // Add all super classes, interface classes and patch class if one |
| 182 // exists to the corresponding lists. | 186 // exists to the corresponding lists. |
| 183 // NOTE: The parse_list array keeps growing as more classes are added | 187 // NOTE: The parse_list array keeps growing as more classes are added |
| 184 // to it by AddRelatedClassesToList. It is not OK to hoist | 188 // to it by AddRelatedClassesToList. It is not OK to hoist |
| (...skipping 22 matching lines...) Expand all Loading... |
| 207 for (intptr_t i = (parse_list.Length() - 1); i >=0 ; i--) { | 211 for (intptr_t i = (parse_list.Length() - 1); i >=0 ; i--) { |
| 208 parse_class ^= parse_list.At(i); | 212 parse_class ^= parse_list.At(i); |
| 209 ASSERT(!parse_class.IsNull()); | 213 ASSERT(!parse_class.IsNull()); |
| 210 ClassFinalizer::FinalizeClass(parse_class); | 214 ClassFinalizer::FinalizeClass(parse_class); |
| 211 parse_class.reset_is_marked_for_parsing(); | 215 parse_class.reset_is_marked_for_parsing(); |
| 212 } | 216 } |
| 213 | 217 |
| 214 isolate->set_long_jump_base(base); | 218 isolate->set_long_jump_base(base); |
| 215 return Error::null(); | 219 return Error::null(); |
| 216 } else { | 220 } else { |
| 221 // Reset the marked for parsing flags. |
| 222 for (intptr_t i = 0; i < parse_list.Length(); i++) { |
| 223 parse_class ^= parse_list.At(i); |
| 224 if (parse_class.is_marked_for_parsing()) { |
| 225 parse_class.reset_is_marked_for_parsing(); |
| 226 } |
| 227 } |
| 228 for (intptr_t i = 0; i < patch_list.Length(); i++) { |
| 229 parse_class ^= patch_list.At(i); |
| 230 if (parse_class.is_marked_for_parsing()) { |
| 231 parse_class.reset_is_marked_for_parsing(); |
| 232 } |
| 233 } |
| 234 |
| 217 Error& error = Error::Handle(); | 235 Error& error = Error::Handle(); |
| 218 error = isolate->object_store()->sticky_error(); | 236 error = isolate->object_store()->sticky_error(); |
| 219 isolate->object_store()->clear_sticky_error(); | 237 isolate->object_store()->clear_sticky_error(); |
| 220 isolate->set_long_jump_base(base); | 238 isolate->set_long_jump_base(base); |
| 221 return error.raw(); | 239 return error.raw(); |
| 222 } | 240 } |
| 223 UNREACHABLE(); | 241 UNREACHABLE(); |
| 224 return Error::null(); | 242 return Error::null(); |
| 225 } | 243 } |
| 226 | 244 |
| (...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 928 Object::Handle(isolate->object_store()->sticky_error()); | 946 Object::Handle(isolate->object_store()->sticky_error()); |
| 929 isolate->object_store()->clear_sticky_error(); | 947 isolate->object_store()->clear_sticky_error(); |
| 930 isolate->set_long_jump_base(base); | 948 isolate->set_long_jump_base(base); |
| 931 return result.raw(); | 949 return result.raw(); |
| 932 } | 950 } |
| 933 UNREACHABLE(); | 951 UNREACHABLE(); |
| 934 return Object::null(); | 952 return Object::null(); |
| 935 } | 953 } |
| 936 | 954 |
| 937 } // namespace dart | 955 } // namespace dart |
| OLD | NEW |