solidity-antlr4
Version:
Solidity Lang Lexer and Parser by official ANTLR4 grammar
75 lines (74 loc) • 2.84 kB
JavaScript
import { BaseNode } from "../base.js";
import {
VariableDeclarationContext,
ParameterDeclarationContext,
StateVariableDeclarationContext,
ConstantVariableDeclarationContext,
EventParameterContext,
ErrorParameterContext
} from "../../antlr4/index.js";
export class VariableDeclaration extends BaseNode {
type = "VariableDeclaration";
name = null;
typeName;
dataLocation = null;
stateVariable = false;
parameter = false;
public = false;
private = false;
internal = false;
constant = false;
immutable = false;
indexed = false;
override = null;
expression = null;
constructor(ctx, visitor) {
super(ctx, visitor);
if (ctx instanceof VariableDeclarationContext) {
this.parameter = true;
this.name = ctx.identifier()?.accept(visitor) ?? null;
this.typeName = ctx.typeName().accept(visitor);
this.dataLocation = ctx.dataLocation()?.accept(visitor) ?? null;
this.stateVariable = false;
this.constant = false;
this.indexed = false;
} else if (ctx instanceof ParameterDeclarationContext) {
this.parameter = true;
this.name = ctx.identifier()?.accept(visitor) ?? null;
this.typeName = ctx.typeName().accept(visitor);
this.dataLocation = ctx.dataLocation()?.accept(visitor) ?? null;
} else if (ctx instanceof StateVariableDeclarationContext) {
this.stateVariable = true;
this.name = ctx.identifier()?.accept(visitor) ?? null;
this.typeName = ctx.typeName().accept(visitor);
this.public = !!ctx.Public().length;
this.private = !!ctx.Private().length;
this.internal = !!ctx.Internal().length;
this.constant = !!ctx.Constant().length;
this.immutable = !!ctx.Immutable().length;
this.override = ctx.overrideSpecifier(0)?.accept(visitor) ?? null;
this.expression = ctx.expression()?.accept(visitor) ?? null;
} else if (ctx instanceof ConstantVariableDeclarationContext) {
this.name = ctx.identifier()?.accept(visitor) ?? null;
this.typeName = ctx.typeName().accept(visitor);
this.constant = true;
this.expression = ctx.expression().accept(visitor);
} else if (ctx instanceof ErrorParameterContext) {
this.parameter = true;
this.name = ctx.identifier()?.accept(visitor) ?? null;
this.typeName = ctx.typeName().accept(visitor);
} else if (ctx instanceof EventParameterContext) {
this.parameter = true;
this.name = ctx.identifier()?.accept(visitor) ?? null;
this.typeName = ctx.typeName().accept(visitor);
this.indexed = !!ctx.Indexed();
}
}
}
export {
VariableDeclaration as ParameterDeclaration,
VariableDeclaration as StateVariableDeclaration,
VariableDeclaration as ConstantVariableDeclaration,
VariableDeclaration as ErrorParameter,
VariableDeclaration as EventParameter
};