This commit is contained in:
Rohan Singh
2019-01-23 22:52:45 -05:00
parent 3f69ec7987
commit ad50a19057
103 changed files with 5734 additions and 1 deletions
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using ScriptConverter.Parser;
namespace ScriptConverter.Ast.Statements
{
class BlockStatement : Statement
{
public ReadOnlyCollection<Statement> Statements { get; private set; }
public bool IsSwitch { get; private set; }
public BlockStatement(ScriptToken start, ScriptToken end, List<Statement> statements, bool isSwitch = false)
: base(start, end)
{
if (statements == null)
throw new ArgumentNullException("statements");
Statements = statements.AsReadOnly();
IsSwitch = isSwitch;
}
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 statement in Statements)
{
statement.SetParent(this);
}
}
}
}
@@ -0,0 +1,23 @@
using ScriptConverter.Parser;
namespace ScriptConverter.Ast.Statements
{
class BreakStatement : Statement
{
public BreakStatement(ScriptToken token)
: base(token)
{
}
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;
}
}
}
@@ -0,0 +1,23 @@
using ScriptConverter.Parser;
namespace ScriptConverter.Ast.Statements
{
class ContinueStatement : Statement
{
public ContinueStatement(ScriptToken token)
: base(token)
{
}
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;
}
}
}
@@ -0,0 +1,31 @@
using ScriptConverter.Ast.Expressions;
using ScriptConverter.Parser;
namespace ScriptConverter.Ast.Statements
{
class DoStatement : Statement
{
public Expression Condition { get; private set; }
public BlockStatement Block { get; private set; }
public DoStatement(ScriptToken start, ScriptToken end, Expression condition, BlockStatement block)
: base(start, end)
{
Condition = condition;
Block = block;
}
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;
Condition.SetParent(null);
Block.SetParent(this);
}
}
}
@@ -0,0 +1,23 @@
using ScriptConverter.Parser;
namespace ScriptConverter.Ast.Statements
{
class EmptyStatement : Statement
{
public EmptyStatement(ScriptToken token)
: base(token)
{
}
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;
}
}
}
@@ -0,0 +1,55 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using ScriptConverter.Ast.Expressions;
using ScriptConverter.Parser;
namespace ScriptConverter.Ast.Statements
{
class ForStatement : Statement
{
public ReadOnlyCollection<Statement> Initializers { get; private set; }
public Expression Condition { get; private set; }
public ReadOnlyCollection<Expression> Increment { get; private set; }
public BlockStatement Block { get; private set; }
public ForStatement(ScriptToken start, ScriptToken end, List<Statement> initializers, Expression condition, List<Expression> increment, BlockStatement block)
: base(start, end)
{
Initializers = initializers != null ? initializers.AsReadOnly() : null;
Condition = condition;
Increment = increment != null ? increment.AsReadOnly() : null;
Block = block;
}
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;
if (Initializers != null)
{
foreach (var statement in Initializers)
{
statement.SetParent(this);
}
}
if (Condition != null)
Condition.SetParent(null);
if (Increment != null)
{
foreach (var expression in Increment)
{
expression.SetParent(null);
}
}
Block.SetParent(this);
}
}
}
@@ -0,0 +1,53 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using ScriptConverter.Ast.Expressions;
using ScriptConverter.Parser;
namespace ScriptConverter.Ast.Statements
{
class IfStatement : Statement
{
public class Branch
{
public Expression Condition { get; private set; }
public BlockStatement Block { get; private set; }
public Branch(Expression condition, BlockStatement block)
{
Condition = condition;
Block = block;
}
}
public ReadOnlyCollection<Branch> Branches { get; private set; }
public Branch DefaultBranch { get; private set; }
public IfStatement(ScriptToken start, ScriptToken end, List<Branch> branches, Branch defaultBranch)
: base(start, end)
{
Branches = branches.AsReadOnly();
DefaultBranch = defaultBranch;
}
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 branch in Branches)
{
branch.Condition.SetParent(null);
branch.Block.SetParent(this);
}
if (DefaultBranch != null)
{
DefaultBranch.Block.SetParent(this);
}
}
}
}
@@ -0,0 +1,27 @@
using ScriptConverter.Ast.Expressions;
namespace ScriptConverter.Ast.Statements
{
class NakedStatement : Statement
{
public Expression Expression { get; private set; }
public NakedStatement(Expression expression)
: base(expression.Start, expression.End)
{
Expression = expression;
}
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;
Expression.SetParent(null);
}
}
}
@@ -0,0 +1,29 @@
using ScriptConverter.Ast.Expressions;
using ScriptConverter.Parser;
namespace ScriptConverter.Ast.Statements
{
class ReturnStatement : Statement
{
public Expression Value { get; private set; }
public ReturnStatement(ScriptToken start, ScriptToken end, Expression value)
: base(start, end)
{
Value = value;
}
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;
if (Value != null)
Value.SetParent(null);
}
}
}
@@ -0,0 +1,25 @@
using System;
using ScriptConverter.Parser;
namespace ScriptConverter.Ast.Statements
{
abstract class Statement
{
public readonly ScriptToken Start;
public readonly ScriptToken End;
public Statement Parent { get; protected set; }
protected Statement(ScriptToken start, ScriptToken end = null)
{
if (start == null)
throw new ArgumentNullException("start");
Start = start;
End = end ?? start;
}
public abstract TStmt Accept<TDoc, TDecl, TStmt, TExpr>(IAstVisitor<TDoc, TDecl, TStmt, TExpr> visitor);
public abstract void SetParent(Statement parent);
}
}
@@ -0,0 +1,55 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using ScriptConverter.Ast.Expressions;
using ScriptConverter.Parser;
namespace ScriptConverter.Ast.Statements
{
class SwitchStatement : Statement
{
public class Branch
{
public ReadOnlyCollection<Expression> Conditions { get; private set; }
public BlockStatement Block { get; private set; }
public Branch(List<Expression> conditions, BlockStatement block)
{
Conditions = conditions.AsReadOnly();
Block = block;
}
}
public Expression Expression { get; private set; }
public ReadOnlyCollection<Branch> Branches { get; private set; }
public SwitchStatement(ScriptToken start, ScriptToken end, Expression expression, List<Branch> branches)
: base(start, end)
{
Expression = expression;
Branches = branches.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;
Expression.SetParent(null);
foreach (var branch in Branches)
{
foreach (var expression in branch.Conditions)
{
if (expression != null)
expression.SetParent(null);
}
branch.Block.SetParent(this);
}
}
}
}
@@ -0,0 +1,28 @@
using ScriptConverter.Ast.Expressions;
using ScriptConverter.Parser;
namespace ScriptConverter.Ast.Statements
{
class ThrowStatement : Statement
{
public Expression Value { get; private set; }
public ThrowStatement(ScriptToken start, Expression value)
: base(start, value.End)
{
Value = value;
}
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;
Value.SetParent(null);
}
}
}
@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using ScriptConverter.Parser;
namespace ScriptConverter.Ast.Statements
{
class TryStatement : Statement
{
public class Branch
{
public ScriptType Type { get; private set; }
public string Name { get; private set; }
public BlockStatement Block { get; private set; }
public Branch(ScriptType type, string name, BlockStatement block)
{
Type = type;
Name = name;
Block = block;
}
}
public BlockStatement Block { get; private set; }
public ReadOnlyCollection<Branch> Branches { get; private set; }
public TryStatement(ScriptToken start, ScriptToken end, BlockStatement block, List<Branch> branches) : base(start, end)
{
if (branches.Count < 1)
throw new ArgumentException("need at least 1 branch", "branches");
Block = block;
Branches = branches.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;
Block.SetParent(this);
foreach (var branch in Branches)
{
branch.Block.SetParent(this);
}
}
}
}
@@ -0,0 +1,56 @@
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);
}
}
}
}
@@ -0,0 +1,31 @@
using ScriptConverter.Ast.Expressions;
using ScriptConverter.Parser;
namespace ScriptConverter.Ast.Statements
{
class WhileStatement : Statement
{
public Expression Condition { get; private set; }
public BlockStatement Block { get; private set; }
public WhileStatement(ScriptToken start, ScriptToken end, Expression condition, BlockStatement block)
: base(start, end)
{
Condition = condition;
Block = block;
}
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;
Condition.SetParent(null);
Block.SetParent(this);
}
}
}