OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 35 matching lines...) Loading... |
46 class Interface : public ZoneObject { | 46 class Interface : public ZoneObject { |
47 public: | 47 public: |
48 // --------------------------------------------------------------------------- | 48 // --------------------------------------------------------------------------- |
49 // Factory methods. | 49 // Factory methods. |
50 | 50 |
51 static Interface* NewValue() { | 51 static Interface* NewValue() { |
52 static Interface value_interface(VALUE + FROZEN); // Cached. | 52 static Interface value_interface(VALUE + FROZEN); // Cached. |
53 return &value_interface; | 53 return &value_interface; |
54 } | 54 } |
55 | 55 |
56 static Interface* NewUnknown() { | 56 static Interface* NewUnknown(Zone* zone) { |
57 return new Interface(NONE); | 57 return new(zone) Interface(NONE); |
58 } | 58 } |
59 | 59 |
60 static Interface* NewModule() { | 60 static Interface* NewModule(Zone* zone) { |
61 return new Interface(MODULE); | 61 return new(zone) Interface(MODULE); |
62 } | 62 } |
63 | 63 |
64 // --------------------------------------------------------------------------- | 64 // --------------------------------------------------------------------------- |
65 // Mutators. | 65 // Mutators. |
66 | 66 |
67 // Add a name to the list of exports. If it already exists, unify with | 67 // Add a name to the list of exports. If it already exists, unify with |
68 // interface, otherwise insert unless this is closed. | 68 // interface, otherwise insert unless this is closed. |
69 void Add(Handle<String> name, Interface* interface, bool* ok) { | 69 void Add(Handle<String> name, Interface* interface, bool* ok, Zone* zone) { |
70 DoAdd(name.location(), name->Hash(), interface, ok); | 70 DoAdd(name.location(), name->Hash(), interface, ok, zone); |
71 } | 71 } |
72 | 72 |
73 // Unify with another interface. If successful, both interface objects will | 73 // Unify with another interface. If successful, both interface objects will |
74 // represent the same type, and changes to one are reflected in the other. | 74 // represent the same type, and changes to one are reflected in the other. |
75 void Unify(Interface* that, bool* ok); | 75 void Unify(Interface* that, bool* ok, Zone* zone); |
76 | 76 |
77 // Determine this interface to be a value interface. | 77 // Determine this interface to be a value interface. |
78 void MakeValue(bool* ok) { | 78 void MakeValue(bool* ok) { |
79 *ok = !IsModule(); | 79 *ok = !IsModule(); |
80 if (*ok) Chase()->flags_ |= VALUE; | 80 if (*ok) Chase()->flags_ |= VALUE; |
81 } | 81 } |
82 | 82 |
83 // Determine this interface to be a module interface. | 83 // Determine this interface to be a module interface. |
84 void MakeModule(bool* ok) { | 84 void MakeModule(bool* ok) { |
85 *ok = !IsValue(); | 85 *ok = !IsValue(); |
(...skipping 23 matching lines...) Loading... |
109 | 109 |
110 // Check whether this is a module type. | 110 // Check whether this is a module type. |
111 bool IsModule() { return Chase()->flags_ & MODULE; } | 111 bool IsModule() { return Chase()->flags_ & MODULE; } |
112 | 112 |
113 // Check whether this is closed (i.e. fully determined). | 113 // Check whether this is closed (i.e. fully determined). |
114 bool IsFrozen() { return Chase()->flags_ & FROZEN; } | 114 bool IsFrozen() { return Chase()->flags_ & FROZEN; } |
115 | 115 |
116 Handle<JSModule> Instance() { return Chase()->instance_; } | 116 Handle<JSModule> Instance() { return Chase()->instance_; } |
117 | 117 |
118 // Look up an exported name. Returns NULL if not (yet) defined. | 118 // Look up an exported name. Returns NULL if not (yet) defined. |
119 Interface* Lookup(Handle<String> name); | 119 Interface* Lookup(Handle<String> name, Zone* zone); |
120 | 120 |
121 // --------------------------------------------------------------------------- | 121 // --------------------------------------------------------------------------- |
122 // Iterators. | 122 // Iterators. |
123 | 123 |
124 // Use like: | 124 // Use like: |
125 // for (auto it = interface->iterator(); !it.done(); it.Advance()) { | 125 // for (auto it = interface->iterator(); !it.done(); it.Advance()) { |
126 // ... it.name() ... it.interface() ... | 126 // ... it.name() ... it.interface() ... |
127 // } | 127 // } |
128 class Iterator { | 128 class Iterator { |
129 public: | 129 public: |
(...skipping 50 matching lines...) Loading... |
180 #endif | 180 #endif |
181 } | 181 } |
182 | 182 |
183 Interface* Chase() { | 183 Interface* Chase() { |
184 Interface* result = this; | 184 Interface* result = this; |
185 while (result->forward_ != NULL) result = result->forward_; | 185 while (result->forward_ != NULL) result = result->forward_; |
186 if (result != this) forward_ = result; // On-the-fly path compression. | 186 if (result != this) forward_ = result; // On-the-fly path compression. |
187 return result; | 187 return result; |
188 } | 188 } |
189 | 189 |
190 void DoAdd(void* name, uint32_t hash, Interface* interface, bool* ok); | 190 void DoAdd(void* name, uint32_t hash, Interface* interface, bool* ok, |
191 void DoUnify(Interface* that, bool* ok); | 191 Zone* zone); |
| 192 void DoUnify(Interface* that, bool* ok, Zone* zone); |
192 }; | 193 }; |
193 | 194 |
194 } } // namespace v8::internal | 195 } } // namespace v8::internal |
195 | 196 |
196 #endif // V8_INTERFACE_H_ | 197 #endif // V8_INTERFACE_H_ |
OLD | NEW |