1// Copyright 2011 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "src/ast/variables.h"
6
7#include "src/ast/scopes.h"
8#include "src/globals.h"
9
10namespace v8 {
11namespace internal {
12
13// ----------------------------------------------------------------------------
14// Implementation Variable.
15
16Variable::Variable(Scope* scope, const AstRawString* name, VariableMode mode,
17                   VariableKind kind, InitializationFlag initialization_flag,
18                   MaybeAssignedFlag maybe_assigned_flag)
19    : scope_(scope),
20      name_(name),
21      local_if_not_shadowed_(nullptr),
22      next_(nullptr),
23      index_(-1),
24      initializer_position_(kNoSourcePosition),
25      bit_field_(MaybeAssignedFlagField::encode(maybe_assigned_flag) |
26                 InitializationFlagField::encode(initialization_flag) |
27                 VariableModeField::encode(mode) | IsUsedField::encode(false) |
28                 ForceContextAllocationField::encode(false) |
29                 LocationField::encode(VariableLocation::UNALLOCATED) |
30                 VariableKindField::encode(kind)) {
31  // Var declared variables never need initialization.
32  DCHECK(!(mode == VAR && initialization_flag == kNeedsInitialization));
33}
34
35
36bool Variable::IsGlobalObjectProperty() const {
37  // Temporaries are never global, they must always be allocated in the
38  // activation frame.
39  return (IsDynamicVariableMode(mode()) ||
40          (IsDeclaredVariableMode(mode()) && !IsLexicalVariableMode(mode()))) &&
41         scope_ != NULL && scope_->is_script_scope();
42}
43
44}  // namespace internal
45}  // namespace v8
46