private void CheckSemanticLocal(MoveInfo treeInfo, ScriptInfo scriptInfo, CheckingInfo checkingInfo) { _funcInfo = scriptInfo.FindLocalFunc(_name); if (_funcInfo == null) // find in includes { _funcInfo = scriptInfo.FindIncludesFunc(_name); if (_funcInfo == null) { scriptInfo.SF.Errors.Add( new SemanticError("Unknown function '" + _name + "'", treeInfo.GetErrorInfo(treeInfo.Current))); return; } if (_funcInfo.Access == MemberAccess.Private) { scriptInfo.SF.Errors.Add( new SemanticError("Cannot access member '" + _funcInfo.ToString() + "'", treeInfo.GetErrorInfo(treeInfo.Current))); } } scriptInfo.References.Add(new FuncRefInfo(scriptInfo.SF, _funcInfo, this.CharIndex, this.CharLength, checkingInfo.SC.SourceCode.Substring(this.CharIndex, this.CharLength), false)); }
public override void CheckSemantic(MoveInfo treeInfo, ScriptInfo scriptInfo, CheckingInfo checkingInfo) { ScriptFile sf = scriptInfo.SF.Manager.GetSF(_usingInfo.SFPath); if (sf == null || sf.SI == null) { scriptInfo.SF.Errors.Add(new SemanticError("Could not find file '" + _usingInfo.SFPath + "'", treeInfo.GetErrorInfo(treeInfo.Current))); } string upperName = this._usingInfo.Name.ToUpperInvariant(); List <IMemberInfo> members = scriptInfo.SF.SI.GetAvailableMembers(); foreach (IMemberInfo m in members) { if (m is UsingInfo && m.Name.ToUpperInvariant() == upperName) { if ((m as UsingInfo) != this._usingInfo) { scriptInfo.SF.Errors.Add( new SemanticError("Using '" + this._usingInfo.Name + "' already defined(" + m.SF.SFPath + "::" + m.Name + ")", treeInfo.GetErrorInfo(treeInfo.Current))); } } } }
private void CheckSemanticLocal(MoveInfo treeInfo, ScriptInfo scriptInfo, CheckingInfo checkingInfo) { _funcInfo = scriptInfo.FindLocalFunc(_name); if (_funcInfo == null) { _funcInfo = scriptInfo.FindGlobalsFunc(_name); } if (_funcInfo == null) // find in includes { _funcInfo = scriptInfo.FindIncludesFunc(_name); if (_funcInfo == null) { scriptInfo.SF.Errors.Add( new SemanticError("Unknown function '" + _name + "'", treeInfo.GetErrorInfo(treeInfo.Current))); return; } if (_funcInfo.Access != MemberAccess.Public) // private member in include { scriptInfo.SF.Errors.Add( new SemanticError("Cannot access function '" + _funcInfo.ToString() + "'", treeInfo.GetErrorInfo(treeInfo.Current))); } } }
private void CheckSemanticExtern(MoveInfo treeInfo, ScriptInfo scriptInfo, CheckingInfo checkingInfo) { _path = _pathOrUsing; #region Finding using UsingInfo usingInfoTry = scriptInfo.FindUsing(_path); if (usingInfoTry != null) { if (usingInfoTry.SF != scriptInfo.SF && usingInfoTry.Access != MemberAccess.Public) { scriptInfo.SF.Errors.Add(new SemanticError("Could not access using '" + usingInfoTry.SF.SFPath + "::" + usingInfoTry.Name + "'", treeInfo.GetErrorInfo(_pathElem))); return; } _path = usingInfoTry.SFPath; UsingName usingName = UsingName.ConvertToMe(this, _pathElem, usingInfoTry); scriptInfo.References.Add(new UsingRefInfo(scriptInfo.SF, usingInfoTry, usingName.CharIndex, usingName.CharLength, checkingInfo.SC.SourceCode.Substring(usingName.CharIndex, usingName.CharLength))); } #endregion ScriptFile sf = scriptInfo.SF.Manager.GetSF(_path); if (sf == null) { scriptInfo.SF.Errors.Add( new SemanticError("Could not find file '" + _path + "'", treeInfo.GetErrorInfo(treeInfo.Current))); return; } else if (sf.SI == null) { scriptInfo.SF.Errors.Add( new WarningError("Could not read file '" + _path + "'", treeInfo.GetErrorInfo(treeInfo.Current))); return; } _funcInfo = sf.SI.FindLocalFunc(_name); if (_funcInfo == null) { scriptInfo.SF.Errors.Add( new SemanticError("Unknown function '" + _path + "::" + _name + "'", treeInfo.GetErrorInfo(treeInfo.Current))); return; } // member is private if (sf != scriptInfo.SF && _funcInfo.Access != MemberAccess.Public) { scriptInfo.SF.Errors.Add( new SemanticError("Cannot access function '" + _path + "::" + _name + "'", treeInfo.GetErrorInfo(treeInfo.Current))); } }
public override void CheckSemantic(MoveInfo treeInfo, ScriptInfo scriptInfo, CheckingInfo checkingInfo) { if (!String.IsNullOrEmpty(_pathOrUsing)) // extern func or extern const { CheckSemanticExtern(treeInfo, scriptInfo, checkingInfo); } else // local or includes func { CheckSemanticLocal(treeInfo, scriptInfo, checkingInfo); } }
public override void CheckSemantic(MoveInfo treeInfo, ScriptInfo scriptInfo, CheckingInfo checkingInfo) { // unreachable code MoveInfo blockInfo = new MoveInfo(treeInfo.CurrentBlock, SearchTree.ContentBlock, treeInfo.CurrentIndex, treeInfo); IElement nextTry = blockInfo.FindNextBlack(SearchDirection.LeftToRight); if (nextTry != null && nextTry is Statement) { scriptInfo.SF.Errors.Add( new WarningError("Unreachable code detected", blockInfo.GetErrorInfo(nextTry))); } }
public override void CheckSemantic(MoveInfo treeInfo, ScriptInfo scriptInfo, CheckingInfo checkingInfo) { if (!String.IsNullOrEmpty(this._pathOrUsing)) { CheckSemanticExtern(treeInfo, scriptInfo, checkingInfo); } else { CheckSemanticLocal(treeInfo, scriptInfo, checkingInfo); } if (_funcInfo != null) { if (Arguments.Count > _funcInfo.Parameters.Count) { if (_funcInfo.SF.IsExtern) // codapi funcs -> only warning { scriptInfo.SF.Errors.Add( new WarningError("Function '" + _funcInfo.ToString() + "' has more arguments than parameters in the definition", treeInfo.GetErrorInfo(treeInfo.Current))); } else { scriptInfo.SF.Errors.Add( new SemanticError("Function '" + _funcInfo.ToString() + "' has more arguments than parameters in the definition", treeInfo.GetErrorInfo(treeInfo.Current))); } } if ((_funcInfo.OptParamStartIndex != null && Arguments.Count < _funcInfo.OptParamStartIndex) || (_funcInfo.OptParamStartIndex == null && Arguments.Count < _funcInfo.Parameters.Count)) { scriptInfo.SF.Errors.Add( new WarningError("Could not find enough arguments, function '" + _funcInfo.ToString() + "'", treeInfo.GetErrorInfo(treeInfo.Current))); } FuncRefInfo funcRefInfo = new FuncRefInfo(scriptInfo.SF, _funcInfo, this.CharIndex, this.CharLength, checkingInfo.SC.SourceCode.Substring(this.CharIndex, this.CharLength), true); foreach (Expression arg in this.Arguments) { funcRefInfo.AddArgument(arg.CharIndex, arg.CharLength); } scriptInfo.References.Add(funcRefInfo); } }
public override void CheckSemantic(MoveInfo treeInfo, ScriptInfo scriptInfo, CheckingInfo checkingInfo) { if (!treeInfo.IsIn <IterationStatement>()) { throw new SyntaxException("Keyword 'continue' cannot use here!", treeInfo.GetErrorInfo()); } // unreachable code MoveInfo blockInfo = new MoveInfo(treeInfo.CurrentBlock, SearchTree.ContentBlock, treeInfo.CurrentIndex, treeInfo); IElement nextTry = blockInfo.FindNextBlack(SearchDirection.LeftToRight); if (nextTry != null && nextTry is Statement) { scriptInfo.SF.Errors.Add( new WarningError("Unreachable code detected", blockInfo.GetErrorInfo(nextTry))); } }
public override void CheckSemantic(MoveInfo treeInfo, ScriptInfo scriptInfo, CheckingInfo checkingInfo) { string upperName = this._constInfo.Name.ToUpperInvariant(); List <IMemberInfo> members = scriptInfo.SF.SI.GetAvailableMembers(); foreach (IMemberInfo m in members) { if (m.Name.ToUpperInvariant() == upperName) { if ((m as ConstInfo) != this._constInfo) { scriptInfo.SF.Errors.Add( new SemanticError("Member '" + this._constInfo.Name + "' already defined(" + m.SF.SFPath + "::" + m.Name + ")", treeInfo.GetErrorInfo(treeInfo.Current))); } } } }
public virtual void CheckSemantic(MoveInfo treeInfo, ScriptInfo scriptInfo, CheckingInfo checkingInfo) { }
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))); }
private void CheckSemanticExtern(MoveInfo treeInfo, ScriptInfo scriptInfo, CheckingInfo checkingInfo) { _path = _pathOrUsing; #region Finding using UsingInfo usingInfoTry = scriptInfo.FindUsing(_path); if (usingInfoTry != null) { if (usingInfoTry.SF != scriptInfo.SF && usingInfoTry.Access != MemberAccess.Public) { scriptInfo.SF.Errors.Add(new SemanticError("Could not access using '" + usingInfoTry.SF.SFPath + "::" + usingInfoTry.Name + "'", treeInfo.GetErrorInfo(this._pathElem))); return; } _path = usingInfoTry.SFPath; UsingName usingName = UsingName.ConvertToMe(this, this._pathElem, usingInfoTry); scriptInfo.References.Add(new UsingRefInfo(scriptInfo.SF, usingInfoTry, usingName.CharIndex, usingName.CharLength, checkingInfo.SC.SourceCode.Substring(usingName.CharIndex, usingName.CharLength))); } #endregion ScriptFile sf = scriptInfo.SF.Manager.GetSF(_path); if (sf == null || sf.SI == null) { scriptInfo.SF.Errors.Add( new SemanticError("Could not find file '" + _path + "'", treeInfo.GetErrorInfo(treeInfo.Current))); return; } else if (sf.SI == null) { scriptInfo.SF.Errors.Add( new WarningError("Could not read file '" + _path + "'", treeInfo.GetErrorInfo(treeInfo.Current))); return; } IMemberInfo member = sf.SI.FindLocalMember(_name); if (member == null) { scriptInfo.SF.Errors.Add( new SemanticError("Unknown member '" + _path + "::" + _name + "'", treeInfo.GetErrorInfo(treeInfo.Current))); return; } // member is private if (sf != scriptInfo.SF && ((member is FuncInfo && ((FuncInfo)member).Access != MemberAccess.Public) || (member is ConstInfo && ((ConstInfo)member).Access != MemberAccess.Public))) { scriptInfo.SF.Errors.Add( new SemanticError("Cannot access member '" + _path + "::" + _name + "'", treeInfo.GetErrorInfo(treeInfo.Current))); } // create constant if (member is ConstInfo) { ToConstant(treeInfo, (ConstInfo)member); scriptInfo.References.Add(new ConstRefInfo(scriptInfo.SF, (ConstInfo)member, this.CharIndex, this.CharLength, checkingInfo.SC.SourceCode.Substring(this.CharIndex, this.CharLength))); return; } else if (member is FuncInfo) { _funcInfo = (FuncInfo)member; scriptInfo.References.Add(new FuncRefInfo(scriptInfo.SF, (FuncInfo)member, this.CharIndex, this.CharLength, checkingInfo.SC.SourceCode.Substring(this.CharIndex, this.CharLength), false)); } else { scriptInfo.SF.Errors.Add( new SemanticError("Unknown member type '" + _path + "::" + _name + "'", treeInfo.GetErrorInfo(treeInfo.Current))); } }