summaryrefslogtreecommitdiff
path: root/deps/v8/src/parsing/preparsed-scope-data.h
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/src/parsing/preparsed-scope-data.h')
-rw-r--r--deps/v8/src/parsing/preparsed-scope-data.h163
1 files changed, 60 insertions, 103 deletions
diff --git a/deps/v8/src/parsing/preparsed-scope-data.h b/deps/v8/src/parsing/preparsed-scope-data.h
index 61d67291a4..25298c4331 100644
--- a/deps/v8/src/parsing/preparsed-scope-data.h
+++ b/deps/v8/src/parsing/preparsed-scope-data.h
@@ -5,23 +5,21 @@
#ifndef V8_PARSING_PREPARSED_SCOPE_DATA_H_
#define V8_PARSING_PREPARSED_SCOPE_DATA_H_
-#include <set>
-#include <unordered_map>
-#include <vector>
-
#include "src/globals.h"
#include "src/handles.h"
-#include "src/objects/shared-function-info.h"
+#include "src/maybe-handles.h"
#include "src/zone/zone-chunk-list.h"
+#include "src/zone/zone-containers.h"
namespace v8 {
namespace internal {
template <typename T>
-class Handle;
+class PodArray;
class PreParser;
class PreParsedScopeData;
+class ZonePreParsedScopeData;
/*
@@ -64,40 +62,15 @@ class PreParsedScopeData;
*/
-class ProducedPreParsedScopeData : public ZoneObject {
+class PreParsedScopeDataBuilder : public ZoneObject {
public:
- class ByteData : public ZoneObject {
- public:
- explicit ByteData(Zone* zone)
- : backing_store_(zone), free_quarters_in_last_byte_(0) {}
-
- void WriteUint32(uint32_t data);
- void WriteUint8(uint8_t data);
- void WriteQuarter(uint8_t data);
-
-#ifdef DEBUG
- // For overwriting previously written data at position 0.
- void OverwriteFirstUint32(uint32_t data);
-#endif
-
- Handle<PodArray<uint8_t>> Serialize(Isolate* isolate);
-
- size_t size() const { return backing_store_.size(); }
+ class ByteData;
- private:
- ZoneChunkList<uint8_t> backing_store_;
- uint8_t free_quarters_in_last_byte_;
- };
-
- // Create a ProducedPreParsedScopeData object which will collect data as we
+ // Create a PreParsedScopeDataBuilder object which will collect data as we
// parse.
- ProducedPreParsedScopeData(Zone* zone, ProducedPreParsedScopeData* parent);
-
- // Create a ProducedPreParsedScopeData which is just a proxy for a previous
- // produced PreParsedScopeData.
- ProducedPreParsedScopeData(Handle<PreParsedScopeData> data, Zone* zone);
+ PreParsedScopeDataBuilder(Zone* zone, PreParsedScopeDataBuilder* parent);
- ProducedPreParsedScopeData* parent() const { return parent_; }
+ PreParsedScopeDataBuilder* parent() const { return parent_; }
// For gathering the inner function data and splitting it up according to the
// laziness boundaries. Each lazy function gets its own
@@ -112,7 +85,7 @@ class ProducedPreParsedScopeData : public ZoneObject {
private:
DeclarationScope* function_scope_;
PreParser* preparser_;
- ProducedPreParsedScopeData* produced_preparsed_scope_data_;
+ PreParsedScopeDataBuilder* builder_;
DISALLOW_COPY_AND_ASSIGN(DataGatheringScope);
};
@@ -148,15 +121,15 @@ class ProducedPreParsedScopeData : public ZoneObject {
bool ContainsInnerFunctions() const;
- // If there is data (if the Scope contains skippable inner functions), move
- // the data into the heap and return a Handle to it; otherwise return a null
- // MaybeHandle.
- MaybeHandle<PreParsedScopeData> Serialize(Isolate* isolate);
-
static bool ScopeNeedsData(Scope* scope);
static bool ScopeIsSkippableFunctionScope(Scope* scope);
private:
+ friend class BuilderProducedPreParsedScopeData;
+
+ virtual MaybeHandle<PreParsedScopeData> Serialize(Isolate* isolate);
+ virtual ZonePreParsedScopeData* Serialize(Zone* zone);
+
void AddSkippableFunction(int start_position, int end_position,
int num_parameters, int num_inner_functions,
LanguageMode language_mode,
@@ -166,88 +139,72 @@ class ProducedPreParsedScopeData : public ZoneObject {
void SaveDataForVariable(Variable* var);
void SaveDataForInnerScopes(Scope* scope);
- ProducedPreParsedScopeData* parent_;
+ PreParsedScopeDataBuilder* parent_;
ByteData* byte_data_;
- ZoneChunkList<ProducedPreParsedScopeData*> data_for_inner_functions_;
+ ZoneChunkList<PreParsedScopeDataBuilder*> data_for_inner_functions_;
// Whether we've given up producing the data for this function.
bool bailed_out_;
- // ProducedPreParsedScopeData can also mask a Handle<PreParsedScopeData>
- // which was produced already earlier. This happens for deeper lazy functions.
- Handle<PreParsedScopeData> previously_produced_preparsed_scope_data_;
+ DISALLOW_COPY_AND_ASSIGN(PreParsedScopeDataBuilder);
+};
- DISALLOW_COPY_AND_ASSIGN(ProducedPreParsedScopeData);
+class ProducedPreParsedScopeData : public ZoneObject {
+ public:
+ // If there is data (if the Scope contains skippable inner functions), move
+ // the data into the heap and return a Handle to it; otherwise return a null
+ // MaybeHandle.
+ virtual MaybeHandle<PreParsedScopeData> Serialize(Isolate* isolate) = 0;
+
+ // If there is data (if the Scope contains skippable inner functions), return
+ // an off-heap ZonePreParsedScopeData representing the data; otherwise
+ // return nullptr.
+ virtual ZonePreParsedScopeData* Serialize(Zone* zone) = 0;
+
+ // Create a ProducedPreParsedScopeData which is a proxy for a previous
+ // produced PreParsedScopeData in zone.
+ static ProducedPreParsedScopeData* For(PreParsedScopeDataBuilder* builder,
+ Zone* zone);
+
+ // Create a ProducedPreParsedScopeData which is a proxy for a previous
+ // produced PreParsedScopeData on the heap.
+ static ProducedPreParsedScopeData* For(Handle<PreParsedScopeData> data,
+ Zone* zone);
+
+ // Create a ProducedPreParsedScopeData which is a proxy for a previous
+ // produced PreParsedScopeData in zone.
+ static ProducedPreParsedScopeData* For(ZonePreParsedScopeData* data,
+ Zone* zone);
};
class ConsumedPreParsedScopeData {
public:
- class ByteData {
- public:
- ByteData()
- : data_(nullptr), index_(0), stored_quarters_(0), stored_byte_(0) {}
-
- // Reading from the ByteData is only allowed when a ReadingScope is on the
- // stack. This ensures that we have a DisallowHeapAllocation in place
- // whenever ByteData holds a raw pointer into the heap.
- class ReadingScope {
- public:
- ReadingScope(ByteData* consumed_data, PodArray<uint8_t>* data)
- : consumed_data_(consumed_data) {
- consumed_data->data_ = data;
- }
- explicit ReadingScope(ConsumedPreParsedScopeData* parent);
- ~ReadingScope() { consumed_data_->data_ = nullptr; }
-
- private:
- ByteData* consumed_data_;
- DisallowHeapAllocation no_gc;
- };
-
- void SetPosition(int position) { index_ = position; }
-
- int32_t ReadUint32();
- uint8_t ReadUint8();
- uint8_t ReadQuarter();
-
- size_t RemainingBytes() const;
-
- // private:
- PodArray<uint8_t>* data_;
- int index_;
- uint8_t stored_quarters_;
- uint8_t stored_byte_;
- };
-
- ConsumedPreParsedScopeData();
- ~ConsumedPreParsedScopeData();
+ // Creates a ConsumedPreParsedScopeData representing the data of an on-heap
+ // PreParsedScopeData |data|.
+ static std::unique_ptr<ConsumedPreParsedScopeData> For(
+ Isolate* isolate, Handle<PreParsedScopeData> data);
- void SetData(Isolate* isolate, Handle<PreParsedScopeData> data);
+ // Creates a ConsumedPreParsedScopeData representing the data of an off-heap
+ // ZonePreParsedScopeData |data|.
+ static std::unique_ptr<ConsumedPreParsedScopeData> For(
+ Zone* zone, ZonePreParsedScopeData* data);
- bool HasData() const { return !data_.is_null(); }
+ virtual ~ConsumedPreParsedScopeData() = default;
- ProducedPreParsedScopeData* GetDataForSkippableFunction(
+ virtual ProducedPreParsedScopeData* GetDataForSkippableFunction(
Zone* zone, int start_position, int* end_position, int* num_parameters,
int* num_inner_functions, bool* uses_super_property,
- LanguageMode* language_mode);
+ LanguageMode* language_mode) = 0;
// Restores the information needed for allocating the Scope's (and its
// subscopes') variables.
- void RestoreScopeAllocationData(DeclarationScope* scope);
+ virtual void RestoreScopeAllocationData(DeclarationScope* scope) = 0;
- private:
- void RestoreData(Scope* scope);
- void RestoreDataForVariable(Variable* var);
- void RestoreDataForInnerScopes(Scope* scope);
-
- Isolate* isolate_;
- Handle<PreParsedScopeData> data_;
- std::unique_ptr<ByteData> scope_data_;
- // When consuming the data, these indexes point to the data we're going to
- // consume next.
- int child_index_;
+ protected:
+ ConsumedPreParsedScopeData() = default;
+ private:
DISALLOW_COPY_AND_ASSIGN(ConsumedPreParsedScopeData);
};