Exemple #1
0
        /// <summary>
        /// Called by the framework after the parse method is called
        /// </summary>
        /// <param name="node">The node returned by this implementations Parse method</param>
        public void OnParseComplete(AstNode node)
        {
            var stmt = node as AssignExpr;

            if (stmt._declarations.IsNullOrEmpty())
            {
                return;
            }
            foreach (var decl in stmt._declarations)
            {
                var exp = decl.Item1;
                if (exp is VariableExpr)
                {
                    var  varExp            = exp as VariableExpr;
                    var  valExp            = decl.Item2;
                    var  name              = varExp.Name;
                    bool registeredTypeVar = false;
                    if (valExp is NewExpr)
                    {
                        var newExp = valExp as NewExpr;
                        if (this.Ctx.Types.Contains(newExp.TypeName))
                        {
                            var type  = this.Ctx.Types.Get(newExp.TypeName);
                            var ltype = LangTypeHelper.ConvertToLangTypeClass(type);
                            this.Ctx.Symbols.DefineVariable(name, ltype);
                            registeredTypeVar = true;
                        }
                    }
                    if (!registeredTypeVar)
                    {
                        this.Ctx.Symbols.DefineVariable(name, LTypes.Object);
                    }
                }
            }
        }
        /// <summary>
        /// Called by the framework after the parse method is called
        /// </summary>
        /// <param name="node">The node returned by this implementations Parse method</param>
        public void OnParseAssignComplete(Expr expr)
        {
            var stmt = expr as AssignMultiExpr;

            if (stmt.Assignments == null || stmt.Assignments.Count == 0)
            {
                return;
            }
            foreach (var assignment in stmt.Assignments)
            {
                var exp = assignment.VarExp;
                if (exp.IsNodeType(NodeTypes.SysVariable))
                {
                    var varExp            = exp as VariableExpr;
                    var valExp            = assignment.ValueExp;
                    var name              = varExp.Name;
                    var registeredTypeVar = false;
                    var ctx = this._parser.Context;
                    if (valExp != null && valExp.IsNodeType(NodeTypes.SysNew))
                    {
                        var newExp = valExp as NewExpr;
                        if (ctx.Types.Contains(newExp.TypeName))
                        {
                            var type  = ctx.Types.Get(newExp.TypeName);
                            var ltype = LangTypeHelper.ConvertToLangTypeClass(type);
                            ctx.Symbols.DefineVariable(name, ltype);
                            registeredTypeVar = true;
                        }
                    }
                    if (!registeredTypeVar)
                    {
                        ctx.Symbols.DefineVariable(name, LTypes.Object);
                    }
                }
            }
        }