-
Notifications
You must be signed in to change notification settings - Fork 23
/
identifier.ts
59 lines (51 loc) · 1.59 KB
/
identifier.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { ASTNode } from "../../ast_node";
import { ExternalReferenceType } from "../../constants";
import { PrimaryExpression } from "./primary_expression";
export class Identifier extends PrimaryExpression {
/**
* Name of the identifier
*/
name: string;
/**
* Id of the referenced declaration
*/
referencedDeclaration: number;
constructor(
id: number,
src: string,
typeString: string,
name: string,
referencedDeclaration: number,
raw?: any
) {
super(id, src, typeString, raw);
this.name = name;
this.referencedDeclaration = referencedDeclaration;
}
/**
* Attribute to access the converted referenced declaration.
*
* Is `undefined` when this is a Solidity internal identifier.
*/
get vReferencedDeclaration(): ASTNode | undefined {
return this.requiredContext.locate(this.referencedDeclaration);
}
set vReferencedDeclaration(value: ASTNode | undefined) {
if (value === undefined) {
this.referencedDeclaration = -1;
} else {
if (!this.requiredContext.contains(value)) {
throw new Error(`Node ${value.type}#${value.id} not belongs to a current context`);
}
this.referencedDeclaration = value.id;
}
}
/**
* Solidity builtin or user-defined reference
*/
get vIdentifierType(): ExternalReferenceType {
return this.vReferencedDeclaration
? ExternalReferenceType.UserDefined
: ExternalReferenceType.Builtin;
}
}