Exemplo n.º 1
0
        public override void CheckSemantic(MoveInfo treeInfo, ScriptInfo scriptInfo, CheckingInfo checkingInfo)
        {
            IElement baseVar     = this.GetChildren()[0];
            string   baseVarName = baseVar.ToString();

            foreach (string tStr in ScriptManager.GlobalVariables)
            {
                if (baseVarName.EqualCode(tStr))
                {
                    return;
                }
            }

            if (checkingInfo.CurrentFunc != null) // inside func
            {
                LocalVarInfo tryVarInfo = checkingInfo.CurrentFunc.LocalVars.Find(a => a.Name.EqualCode(baseVarName));
                if (tryVarInfo != null && this.CharIndex >= tryVarInfo.StartIndex)
                {
                    // check "var = var;" | "var[5] = var[5] + 10"; | etc.
                    if (tryVarInfo.VarNameDef == null) // it is reference
                    {
                        tryVarInfo.RefCount++;
                        return;
                    }
                    else if (tryVarInfo.VarNameDef == this) // it is definition
                    {
                        return;
                    }
                    else if (tryVarInfo.AssignDef == null) // it is reference
                    {
                        tryVarInfo.RefCount++;
                        return;
                    }
                    else if (!treeInfo.IsInBlock(tryVarInfo.AssignDef)) // it is reference
                    {
                        tryVarInfo.RefCount++;
                        return;
                    }
                }
            }

            ConstInfo constInfo = scriptInfo.FindLocalConst(baseVarName);

            if (constInfo == null)
            {
                constInfo = scriptInfo.FindIncludesConst(baseVarName);
                if (constInfo == null)
                {
                    constInfo = scriptInfo.FindGlobalsConst(baseVarName);
                    if (constInfo == null)
                    {
                        scriptInfo.SF.Errors.Add(
                            new SemanticError("Unknown variable/constant '" + baseVarName + "'",
                                              treeInfo.GetErrorInfo(treeInfo.Current)));
                        return;
                    }
                }

                if (constInfo.Access == MemberAccess.Private)
                {
                    scriptInfo.SF.Errors.Add(
                        new SemanticError("Cannot access member '" + baseVarName + "'",
                                          treeInfo.GetErrorInfo(treeInfo.Current)));
                }
            }

            ToConstant(treeInfo, constInfo);
            scriptInfo.References.Add(new ConstRefInfo(scriptInfo.SF, constInfo,
                                                       this.CharIndex, this.CharLength, checkingInfo.SC.SourceCode.Substring(this.CharIndex, this.CharLength)));
        }