2 Copyright (C) 2015 Yusuke Suzuki <utatane.tea@gmail.com>
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
13 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
17 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 const RW = READ | WRITE;
31 * A Reference represents a single occurrence of an identifier in code.
35 constructor(ident, scope, flag, writeExpr, maybeImplicitGlobal, partial, init) {
38 * Identifier syntax node.
39 * @member {espreeIdentifier} Reference#identifier
41 this.identifier = ident;
44 * Reference to the enclosing Scope.
45 * @member {Scope} Reference#from
50 * Whether the reference comes from a dynamic scope (such as 'eval',
51 * 'with', etc.), and may be trapped by dynamic scopes.
52 * @member {boolean} Reference#tainted
57 * The variable this reference is resolved with.
58 * @member {Variable} Reference#resolved
63 * The read-write mode of the reference. (Value is one of {@link
64 * Reference.READ}, {@link Reference.RW}, {@link Reference.WRITE}).
65 * @member {number} Reference#flag
72 * If reference is writeable, this is the tree being written to it.
73 * @member {espreeNode} Reference#writeExpr
75 this.writeExpr = writeExpr;
78 * Whether the Reference might refer to a partial value of writeExpr.
79 * @member {boolean} Reference#partial
81 this.partial = partial;
84 * Whether the Reference is to write of initialization.
85 * @member {boolean} Reference#init
89 this.__maybeImplicitGlobal = maybeImplicitGlobal;
93 * Whether the reference is static.
94 * @method Reference#isStatic
95 * @returns {boolean} static
98 return !this.tainted && this.resolved && this.resolved.scope.isStatic();
102 * Whether the reference is writeable.
103 * @method Reference#isWrite
104 * @returns {boolean} write
107 return !!(this.flag & Reference.WRITE);
111 * Whether the reference is readable.
112 * @method Reference#isRead
113 * @returns {boolean} read
116 return !!(this.flag & Reference.READ);
120 * Whether the reference is read-only.
121 * @method Reference#isReadOnly
122 * @returns {boolean} read only
125 return this.flag === Reference.READ;
129 * Whether the reference is write-only.
130 * @method Reference#isWriteOnly
131 * @returns {boolean} write only
134 return this.flag === Reference.WRITE;
138 * Whether the reference is read-write.
139 * @method Reference#isReadWrite
140 * @returns {boolean} read write
143 return this.flag === Reference.RW;
148 * @constant Reference.READ
151 Reference.READ = READ;
154 * @constant Reference.WRITE
157 Reference.WRITE = WRITE;
160 * @constant Reference.RW
165 module.exports = Reference;
167 /* vim: set sw=4 ts=4 et tw=80 : */