Files
SWG-ScriptConverter/ScriptConverter/Ast/Statements/VariableStatement.cs
T
2019-01-23 22:52:45 -05:00

57 lines
1.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using ScriptConverter.Ast.Expressions;
using ScriptConverter.Parser;
namespace ScriptConverter.Ast.Statements
{
class VariableStatement : Statement
{
public class Definition
{
public ScriptType Type { get; private set; }
public string Name { get; private set; }
public Expression Value { get; private set; }
public Definition(ScriptType type, string name, Expression value)
{
Type = type;
Name = name;
Value = value;
}
}
public ScriptType BaseType { get; private set; }
public bool Final { get; private set; }
public ReadOnlyCollection<Definition> Definitions { get; private set; }
public VariableStatement(ScriptToken start, ScriptToken end, ScriptType baseType, bool final, List<Definition> definitions)
: base(start, end)
{
if (definitions.Count < 1)
throw new ArgumentException("need at least 1 definition", "definitions");
BaseType = baseType;
Final = final;
Definitions = definitions.AsReadOnly();
}
public override TStmt Accept<TDoc, TDecl, TStmt, TExpr>(IAstVisitor<TDoc, TDecl, TStmt, TExpr> visitor)
{
return visitor.Visit(this);
}
public override void SetParent(Statement parent)
{
Parent = parent;
foreach (var definition in Definitions)
{
if (definition.Value != null)
definition.Value.SetParent(null);
}
}
}
}