// Copyright 2012 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef V8_COMPILER_H_ #define V8_COMPILER_H_ #include "src/allocation.h" #include "src/ast.h" #include "src/bailout-reason.h" #include "src/zone.h" namespace v8 { namespace internal { class AstValueFactory; class HydrogenCodeStub; // ParseRestriction is used to restrict the set of valid statements in a // unit of compilation. Restriction violations cause a syntax error. enum ParseRestriction { NO_PARSE_RESTRICTION, // All expressions are allowed. ONLY_SINGLE_FUNCTION_LITERAL // Only a single FunctionLiteral expression. }; struct OffsetRange { OffsetRange(int from, int to) : from(from), to(to) {} int from; int to; }; class ScriptData { public: ScriptData(const byte* data, int length); ~ScriptData() { if (owns_data_) DeleteArray(data_); } const byte* data() const { return data_; } int length() const { return length_; } bool rejected() const { return rejected_; } void Reject() { rejected_ = true; } void AcquireDataOwnership() { DCHECK(!owns_data_); owns_data_ = true; } void ReleaseDataOwnership() { DCHECK(owns_data_); owns_data_ = false; } private: bool owns_data_ : 1; bool rejected_ : 1; const byte* data_; int length_; DISALLOW_COPY_AND_ASSIGN(ScriptData); }; // CompilationInfo encapsulates some information known at compile time. It // is constructed based on the resources available at compile-time. class CompilationInfo { public: // Various configuration flags for a compilation, as well as some properties // of the compiled code produced by a compilation. enum Flag { kLazy = 1 << 0, kEval = 1 << 1, kGlobal = 1 << 2, kStrictMode = 1 << 3, kStrongMode = 1 << 4, kThisHasUses = 1 << 5, kNative = 1 << 6, kDeferredCalling = 1 << 7, kNonDeferredCalling = 1 << 8, kSavesCallerDoubles = 1 << 9, kRequiresFrame = 1 << 10, kMustNotHaveEagerFrame = 1 << 11, kDeoptimizationSupport = 1 << 12, kDebug = 1 << 13, kCompilingForDebugging = 1 << 14, kParseRestriction = 1 << 15, kSerializing = 1 << 16, kContextSpecializing = 1 << 17, kInliningEnabled = 1 << 18, kTypingEnabled = 1 << 19, kDisableFutureOptimization = 1 << 20, kModule = 1 << 21, kToplevel = 1 << 22, kSplittingEnabled = 1 << 23 }; CompilationInfo(Handle closure, Zone* zone); CompilationInfo(Handle