예제 #1
0
 public Variable(IdentifierNode identifier, TypeNameNode typeName, BlockStatementNode scope)
 {
     if (identifier == null)
         throw new ArgumentNullException("identifier", "The identifier is null!");
     if (typeName == null) 
         throw new ArgumentNullException("typeName", "The typeName is null!");
     if (scope == null) 
         throw new ArgumentNullException("scope", "The scope is null!");
     
     Identifier = identifier;
     TypeName = typeName;
     Scope = scope;
 }
예제 #2
0
        public IfStatementNode(ExpressionNode condition, BlockStatementNode trueStatement, BlockStatementNode falseStatement, IEnumerable<AttributeNode> attributes)
        {
            if (condition == null) throw new ArgumentNullException("condition");
            if (trueStatement == null) throw new ArgumentNullException("trueStatement");
            if (falseStatement == null) throw new ArgumentNullException("falseStatement");
            if (attributes == null)
                ThrowHelper.ThrowArgumentNullException(() => attributes);

            ConditionExpression = condition;
            TrueStatementNode = trueStatement;
            FalseStatementNode = falseStatement;
            Attributes = attributes.ToList();

            AddChildren(condition, trueStatement, falseStatement);
            AddChildren(Attributes);
        }
        public MacroDeclarationStatementNode(string identifier, IEnumerable<MacroFormalParameterNode> formalParameters, BlockStatementNode body, MacroType macroType)
            : base(identifier)
        {
            if (body == null)
                ThrowHelper.ThrowArgumentNullException(() => body);

            if (formalParameters == null)
                ThrowHelper.ThrowArgumentNullException(() => formalParameters);

            if (body == null)
                ThrowHelper.ThrowArgumentNullException(() => body);

            FormalParameters = formalParameters.ToArray();
            Body = body;
            MacroType = macroType;

            AddChildren(Body);
        }
        public FunctionDeclarationStatementNode(string name, BlockStatementNode functionBody, TypeNameNode returnType, FormalParameterNode[] parameters, IEnumerable<AttributeNode> attributes)
            : base(name)
        {
            if (functionBody == null)
                ThrowHelper.ThrowArgumentNullException(() => functionBody);
            if (returnType == null)
                ThrowHelper.ThrowArgumentNullException(() => returnType);
            if (parameters == null)
                ThrowHelper.ThrowArgumentNullException(() => parameters);
            if (attributes == null)
                ThrowHelper.ThrowArgumentNullException(() => attributes);

            FunctionBody = functionBody;
            ReturnType = returnType;
            Parameters = parameters;
            Attributes = attributes.ToList();

            AddChildren(FunctionBody, ReturnType);
            AddChildren(Parameters);
            AddChildren(Attributes);
        }
예제 #5
0
        public IfStatementNode IfThenElse(ExpressionNode condition, BlockStatementNode trueStatement, IfStatementNode[] elseIfStatements, BlockStatementNode falseStatement, IEnumerable<AttributeNode> attributes)
        {
            if (condition == null)
                ThrowHelper.ThrowArgumentNullException(() => condition);
            if (trueStatement == null)
                ThrowHelper.ThrowArgumentNullException(() => trueStatement);

            if (falseStatement == null)
                falseStatement = EmptyBlock();

            if (elseIfStatements.Any())
            {
                var elseIf = elseIfStatements.First();
                falseStatement =
                    Block(
                        new StatementNodeBase[]{
                                                   IfThenElse(elseIf.ConditionExpression, elseIf.TrueStatementNode, elseIfStatements.Skip(1).ToArray(), new AttributeNode[0])
                                               }
                    );
            }

            return new IfStatementNode(condition, trueStatement, falseStatement, attributes);
        }
예제 #6
0
 public IfStatementNode IfThenElse(ExpressionNode condition, BlockStatementNode trueStatement, IfStatementNode[] elseIfStatements, IEnumerable<AttributeNode> attributes)
 {
     return IfThenElse(condition, trueStatement, elseIfStatements, EmptyBlock(), attributes);
 }
예제 #7
0
        public CompilationUnit CompilationUnit(BlockStatementNode block)
        {
            if (block == null)
                ThrowHelper.ThrowArgumentNullException(() => block);

            return new CompilationUnit(block.Statements);
        }
예제 #8
0
 public MacroDeclarationStatementNode ExplicitMacro(string identifier, IEnumerable<MacroFormalParameterNode> formalParameters, BlockStatementNode body)
 {
     return Macro(identifier, formalParameters, body, MacroType.Explicit);
 }
예제 #9
0
        public MacroDeclarationStatementNode Macro(string identifier, IEnumerable<MacroFormalParameterNode> formalParameters, BlockStatementNode body, MacroType type)
        {
            if (string.IsNullOrWhiteSpace(identifier))
                ThrowHelper.ThrowException("The identifier is blank!");

            if (formalParameters == null)
                ThrowHelper.ThrowArgumentNullException(() => formalParameters);

            if (body == null)
                ThrowHelper.ThrowArgumentNullException(() => body);

            return new MacroDeclarationStatementNode(identifier, formalParameters, body, type);
        }
예제 #10
0
        public FunctionDeclarationStatementNode Function(string name, TypeNameNode returnType, FormalParameterNode[] parameters, BlockStatementNode body, AttributeNode[] attributes)
        {
            if (string.IsNullOrWhiteSpace(name))
                ThrowHelper.ThrowException("The 'name' is blank!");

            if (body == null)
                ThrowHelper.ThrowArgumentNullException(() => body);
            if (parameters == null)
                ThrowHelper.ThrowArgumentNullException(() => parameters);
            if (attributes == null)
                ThrowHelper.ThrowArgumentNullException(() => attributes);

            var type = returnType ?? new TypeNameNode("void");

            return new FunctionDeclarationStatementNode(name, body, type, parameters, attributes);
        }