﻿using AbstractCode.Ast.Expressions;

namespace AbstractCode.Ast.CSharp.Expressions
{
    public class UncheckedExpression : CSharpExpression
    {
        public UncheckedExpression()
        {
        }

        public UncheckedExpression(Expression targetExpression)
        {
            TargetExpression = targetExpression;
        }

        public AstToken UncheckedKeyword
        {
            get { return GetChildByTitle(AstNodeTitles.Keyword); }
            set { SetChildByTitle(AstNodeTitles.Keyword, value); }
        }

        public AstToken LeftParenthese
        {
            get { return GetChildByTitle(AstNodeTitles.LeftParenthese); }
            set { SetChildByTitle(AstNodeTitles.LeftParenthese, value); }
        }

        public Expression TargetExpression
        {
            get { return GetChildByTitle(AstNodeTitles.TargetExpression); }
            set { SetChildByTitle(AstNodeTitles.TargetExpression, value); }
        }

        public AstToken RightParenthese
        {
            get { return GetChildByTitle(AstNodeTitles.RightParenthese); }
            set { SetChildByTitle(AstNodeTitles.RightParenthese, value); }
        }

        public override bool Match(AstNode other)
        {
            var expression = other as UncheckedExpression;
            return expression != null
                   && TargetExpression.MatchOrNull(expression.TargetExpression);
        }

        public override void AcceptVisitor(ICSharpAstVisitor visitor)
        {
            visitor.VisitUncheckedExpression(this);
        }

        public override TResult AcceptVisitor<TResult>(ICSharpAstVisitor<TResult> visitor)
        {
            return visitor.VisitUncheckedExpression(this);
        }

        public override TResult AcceptVisitor<TData, TResult>(ICSharpAstVisitor<TData, TResult> visitor, TData data)
        {
            return visitor.VisitUncheckedExpression(this, data);
        }
    }
}