예제 #1
0
 /// <summary>
 /// Init new variable declaration.
 /// </summary>
 /// <param name="position">Position.</param>
 /// <param name="vartype">Variable type.</param>
 /// <param name="varname">Variable name.</param>
 /// <param name="value">Variable initial value.</param>
 public VariableDecl(ExprPosition position, ExpressionType vartype, string varname, Expression value)
     : base(position)
 {
     this.VariableName = varname;
     this.VariableType = vartype;
     this.InitialValue = value;
 }
예제 #2
0
        public StringLiteral(ExprPosition position, string value)
            : base(position)
        {
            Debug.Assert(value != null);

            this.Value = value;
        }
예제 #3
0
 public ExpressionAssign(ExprPosition position, Expression lValue, Expression rValue)
     : base(position, lValue, rValue)
 {
     if (!(lValue is VariableUse))
     {
         throw new ArgumentException("L-Value must be a VariableUse.");
     }
 }
예제 #4
0
        public ClassDecl(ExprPosition position, string classname, List <VariableDecl> properties)
            : base(position)
        {
            Debug.Assert(!String.IsNullOrEmpty(classname));

            this.ClassName       = classname;
            this.ClassProperties = properties;
        }
예제 #5
0
 public MethodDecl(ExprPosition position, string methodname, List <VariableDecl> arguments, Expression body)
     : base(position)
 {
     this.DeclMethodName      = methodname;
     this.GeneratedMethodName = methodname + "_" + position.StartLine + "_" + position.StartColumn;
     this.MethodArguments     = arguments;
     this.Body = body;
 }
예제 #6
0
 public MethodDecl(ExprPosition position, string methodname, List <VariableDecl> arguments, string bodycsharp, ExpressionType ReturnType)
     : base(position)
 {
     this.DeclMethodName      = methodname;
     this.GeneratedMethodName = methodname + "_" + position.StartLine + "_" + position.StartColumn;
     this.MethodArguments     = arguments;
     this.BodyCSharp          = bodycsharp;
     this.ReturnType          = ReturnType;
 }
예제 #7
0
        public TernaryCondExpression(ExprPosition position, Expression condition, Expression expr1, Expression expr2)
            : base(position)
        {
            if (condition == null || expr1 == null || expr2 == null)
            {
                throw new ArgumentNullException();
            }

            this.ConditionExpr = condition;
            this.Expr1         = expr1;
            this.Expr2         = expr2;
        }
예제 #8
0
        /// <summary>
        /// Init declarations list with one class declaration.
        /// </summary>
        /// <param name="position"></param>
        /// <param name="classdecl"></param>
        public DeclarationsList(ExprPosition position, DeclarationsList decls, ClassDecl classdecl)
            : this(position)
        {
            if (decls != null)
            {
                Classes = decls.Classes;
                Methods.AddRange(decls.Methods);
            }

            if (classdecl != null)
            {
                Classes.Add(classdecl.ClassName, classdecl);
            }
        }
예제 #9
0
            public ExpressionType GetLocalVarType(ExprPosition position, string varname)
            {
                if (string.IsNullOrEmpty(varname))
                {
                    return(null);
                }

                string[] chainName = varname.Split(new char[] { '.' });

                ExpressionType retType;

                if (!DeclaredLocalVars.TryGetValue(chainName[0], out retType))
                {
                    return(null);
                }

                if (chainName.Length > 1)
                {
                    for (int i = 1; i < chainName.Length; ++i)
                    {
                        if (retType.UserTypeName == null)
                        {
                            throw new GeneratorException(position, "Member chain of non-user class not supported.");
                        }

                        ClassDecl classdecl;
                        if (!Declarations.Classes.TryGetValue(retType.UserTypeName, out classdecl))
                        {
                            throw new GeneratorException(position, "Undeclared type " + retType.UserTypeName);
                        }

                        retType = classdecl.ContainsProperty(chainName[i]);

                        if (retType == null)
                        {
                            throw new GeneratorException(position, "Undeclared property " + chainName[i]);
                        }
                    }
                }

                return(retType);
            }
예제 #10
0
        /// <summary>
        /// Init declarations list with one method declaration.
        /// </summary>
        /// <param name="position"></param>
        /// <param name="methoddecl"></param>
        public DeclarationsList(ExprPosition position, DeclarationsList decls, MethodDecl methoddecl)
            : this(position)
        {
            if (decls != null)
            {
                Classes = decls.Classes;
                Methods.AddRange(decls.Methods);
            }

            if (methoddecl != null)
            {
                if (!methoddecl.IsMainMethod)
                {
                    foreach (var m in Methods)
                    {
                        if (m.DeclMethodName == methoddecl.DeclMethodName)
                        { // arguments must match
                            if (m.MethodArguments.Count != methoddecl.MethodArguments.Count)
                            {
                                throw new GeneratorException(position, "Methods " + methoddecl.DeclMethodName + ": Arguments mishmash.");
                            }

                            for (int arg = 0; arg < m.MethodArguments.Count; ++arg)
                            {
                                if (!m.MethodArguments[arg].VariableType.Equals(methoddecl.MethodArguments[arg].VariableType))
                                {
                                    throw new GeneratorException(position, "Methods " + methoddecl.DeclMethodName + ": Arguments mishmash.");
                                }
                                if (m.MethodArguments[arg].VariableName != methoddecl.MethodArguments[arg].VariableName)
                                {
                                    throw new GeneratorException(position, "Methods " + methoddecl.DeclMethodName + ": Arguments mishmash.");
                                }
                            }
                        }
                    }
                }

                Methods.Insert(0, methoddecl);
            }
        }
예제 #11
0
 public ExpressionSubOneBefore(ExprPosition position, Expression value)
     : base(position, value)
 {
 }
예제 #12
0
 public ExpressionAddElement(ExprPosition position, VariableUse lvalue, Expression rvalue)
     : base(position)
 {
     this.lvalue = lvalue;
     this.rvalue = rvalue;
 }
예제 #13
0
 /// <summary>
 /// Constructs the expression node.
 /// </summary>
 /// <param name="position"></param>
 public Expression(ExprPosition position)
 {
     this.Position = position;
 }
예제 #14
0
 public CustomExpression(ExprPosition position, ExpressionType exprType, string csCode)
     : base(position)
 {
     this.CsCode   = csCode;
     this.ExprType = exprType;
 }
예제 #15
0
 public TypeCastExpression(ExprPosition position, ExpressionType newType, Expression expr)
     : base(position, expr)
 {
     this.NewType = newType;
 }
예제 #16
0
 public ExpressionLogicalXor(ExprPosition position, Expression lValue, Expression rValue)
     : base(position, lValue, rValue)
 {
 }
예제 #17
0
 public MethodCall(ExprPosition position, string methodName, List <Expression> callArguments)
     : base(position)
 {
     this.MethodName    = methodName;
     this.CallArguments = callArguments;
 }
예제 #18
0
 public ExpressionLogicalNot(ExprPosition position, Expression value)
     : base(position, value)
 {
 }
예제 #19
0
 public ExpressionGreaterEq(ExprPosition position, Expression lValue, Expression rValue)
     : base(position, lValue, rValue)
 {
 }
예제 #20
0
 /// <summary>
 /// Init empty declarations list.
 /// </summary>
 /// <param name="position"></param>
 public DeclarationsList(ExprPosition position)
     : base(position)
 {
 }
예제 #21
0
 public ExpressionSubOneAfter(ExprPosition position, Expression value)
     : base(position, value)
 {
 }
예제 #22
0
 /// <summary>
 /// Constructs a binary expression.
 /// </summary>
 /// <param name="position">Expression position.</param>
 /// <param name="lValue">Left operand.</param>
 /// <param name="rValue">Right operand.</param>
 public BinaryExpr(ExprPosition position, Expression lValue, Expression rValue)
     : base(position)
 {
     this.LValue = lValue;
     this.RValue = rValue;
 }
예제 #23
0
 /// <summary>
 /// Unary expression initialization.
 /// </summary>
 /// <param name="position"></param>
 /// <param name="value"></param>
 public UnaryExpr(ExprPosition position, Expression value)
     : base(position)
 {
     this.Value = value;
 }
예제 #24
0
 public ExpressionSub(ExprPosition position, Expression lValue, Expression rValue)
     : base(position, lValue, rValue)
 {
 }
예제 #25
0
 public ExpressionUnaryMinus(ExprPosition position, Expression value)
     : base(position, value)
 {
 }
예제 #26
0
 /// <summary>
 /// Init exception.
 /// </summary>
 /// <param name="position"></param>
 /// <param name="message"></param>
 public GeneratorException(ExprPosition position, string message)
     : base(message)
 {
     this.Position = position;
 }
예제 #27
0
 /// <summary>
 /// Init new variable declaration.
 /// </summary>
 /// <param name="position">Position.</param>
 /// <param name="vartype">Type of the variable/property.</param>
 /// <param name="varname">Name of the variable/property.</param>
 public VariableDecl(ExprPosition position, ExpressionType vartype, string varname)
     : this(position, vartype, varname, null)
 {
 }
예제 #28
0
 public VariableUse(ExprPosition position, string name)
     : base(position)
 {
     VariableName = name;
 }
예제 #29
0
 public Statement(ExprPosition position, Expression expr)
     : base(position)
 {
     ExpressionInside = expr;
 }
예제 #30
0
 /// <summary>
 /// Create statements block.
 /// </summary>
 /// <param name="position"></param>
 /// <param name="statements"></param>
 public CodeBlock(ExprPosition position, List <Expression> statements)
     : base(position)
 {
     this.Statements = (statements != null) ? statements : new List <Expression>();
 }