public ScriptQualifiedName(AstNodeArgs args) : base(args) { IsVariable = false; NextFirst = false; IsVar = false; if (ChildNodes.Count == 2 && ChildNodes[1].ChildNodes.Count == 0) { _identifier = ExtractId(((TokenAst)ChildNodes[0]).Text); IsVariable = true; _evaluation = EvaluateIdentifier; _assignment = AssignIdentifier; } else if (ChildNodes[0] is TokenAst && ChildNodes[1].ChildNodes.Count != 0) { _identifier = ExtractId(((TokenAst)ChildNodes[0]).Text); //NOTE: There might be two cases: // 1) a()[]...() // 2) a<>.(NamePart) _modifiers = new List <ScriptAst>(); foreach (ScriptAst node in ChildNodes[1].ChildNodes) { _modifiers.Add(node); } var generic = _modifiers.FirstOrDefault() as ScriptGenericsPostfix; if (generic != null && _modifiers.Count == 1) { //Case 2 _evaluation = EvaluateGenericType; _assignment = null; } else { //Case 1 _evaluation = EvaluateFunctionCall; _assignment = AssignArray; } } else { _namePart = ChildNodes[0] as ScriptQualifiedName; _identifier = ExtractId(((TokenAst)ChildNodes[2]).Text); NextFirst = true; if (ChildNodes.Count == 4 && ChildNodes[3].ChildNodes.Count != 0) { _modifiers = new List <ScriptAst>(); foreach (ScriptAst node in ChildNodes[3].ChildNodes) { _modifiers.Add(node); } } _evaluation = EvaluateNamePart; _assignment = AssignNamePart; } }
public ScriptAssignExpr(AstNodeArgs args) : base(args) { var varExpr = args.ChildNodes[0] as ScriptVarExpr; if (varExpr != null) { var id = varExpr.ChildNodes[1] as TokenAst; _nameExpr = new ScriptQualifiedName(new AstNodeArgs(args.Term, args.Span, new AstNodeList { id, new AstNode(new AstNodeArgs(args.Term, new SourceSpan(new SourceLocation(0, 0, 0), 0), new AstNodeList())) })) { IsVar = true }; } else { _nameExpr = (ScriptQualifiedName)args.ChildNodes[0]; } _oper = ((TokenAst)args.ChildNodes[1]).Text; if (args.ChildNodes.Count == 3) _rightExpr = (ScriptExpr)args.ChildNodes[2]; Debug.Assert(_oper == "=" || _oper == ":=" || _oper == "+=" || _oper == "-=" || _oper == "++" || _oper == "--" || _oper == ":="); switch (_oper) { case "=": _assignOperation = Assign; break; case ":=": _assignOperation = AssignEx; break; case "++": _assignOperation = PlusPlus; break; case "--": _assignOperation = MinusMinus; break; case "+=": _assignOperation = PlusEqual; break; case "-=": _assignOperation = MinusEqual; break; default: throw new System.InvalidOperationException(string.Format(Strings.AssignmentOperatorNotSupported, _oper)); } _minus = RuntimeHost.GetBinaryOperator(OperatorCodes.Sub); _plus = RuntimeHost.GetBinaryOperator(OperatorCodes.Add); if (_plus == null || _minus == null) throw new ScriptRuntimeException(string.Format(Strings.MissingOperatorError, "+,-")); }
private void ScopeBeforeSetItem(IScriptScope sender, ScopeArgs args) { //TODO: Performance improvement. Should be evaluated once per function call List <string> globalNames = GetGlobalNames(_activeContext); if (globalNames.Contains(args.Name)) { ScriptQualifiedName.SetToParentScope(sender.Parent, args.Name, args.Value); args.Cancel = true; } //if (!sender.HasVariable(args.Name)) //{ // args.Cancel = SetToParentScope(sender.Parent, args.Name, args.Value); //} }
private void ScopeBeforeSetItem(IScriptScope sender, ScopeArgs args) { if (_globalNames.Contains(args.Name)) { switch (args.Operation) { case ScopeOperation.Set: ScriptQualifiedName.SetToParentScope(sender.Parent, args.Name, args.Value); args.Cancel = true; break; case ScopeOperation.Create: throw new ScriptExecutionException(string.Format(Strings.LocalIdConflictWithGlobalList, args.Name)); default: break; } } }
public ScriptQualifiedName(AstNodeArgs args) : base(args) { IsVariable = false; NextFirst = false; IsVar = false; if (ChildNodes.Count == 2 && ChildNodes[1].ChildNodes.Count == 0) { _identifier = ExtractId(((TokenAst)ChildNodes[0]).Text); IsVariable = true; _evaluation = EvaluateIdentifier; _assignment = AssignIdentifier; } else if (ChildNodes[0] is TokenAst && ChildNodes[1].ChildNodes.Count != 0) { _identifier = ExtractId(((TokenAst)ChildNodes[0]).Text); //NOTE: There might be two cases: // 1) a()[]...() // 2) a<>.(NamePart) _modifiers = new List<ScriptAst>(); foreach (ScriptAst node in ChildNodes[1].ChildNodes) _modifiers.Add(node); var generic = _modifiers.FirstOrDefault() as ScriptGenericsPostfix; if (generic != null && _modifiers.Count == 1) { //Case 2 _evaluation = EvaluateGenericType; _assignment = null; } else { //Case 1 _evaluation = EvaluateFunctionCall; _assignment = AssignArray; } } else { _namePart = ChildNodes[0] as ScriptQualifiedName; _identifier = ExtractId(((TokenAst)ChildNodes[2]).Text); NextFirst = true; if (ChildNodes.Count == 4 && ChildNodes[3].ChildNodes.Count != 0) { _modifiers = new List<ScriptAst>(); foreach (ScriptAst node in ChildNodes[3].ChildNodes) { _modifiers.Add(node); } } _evaluation = EvaluateNamePart; _assignment = AssignNamePart; } }
public ScriptUsingStatement(AstNodeArgs args) : base(args) { _name = args.ChildNodes[1] as ScriptQualifiedName; _statement = args.ChildNodes[2] as ScriptAst; }
public ScriptAssignExpr(AstNodeArgs args) : base(args) { var varExpr = args.ChildNodes[0] as ScriptVarExpr; if (varExpr != null) { var id = varExpr.ChildNodes[1] as TokenAst; _nameExpr = new ScriptQualifiedName(new AstNodeArgs(args.Term, args.Span, new AstNodeList { id, new AstNode(new AstNodeArgs(args.Term, new SourceSpan(new SourceLocation(0, 0, 0), 0), new AstNodeList())) })) { IsVar = true }; } else { _nameExpr = (ScriptQualifiedName)args.ChildNodes[0]; } _oper = ((TokenAst)args.ChildNodes[1]).Text; if (args.ChildNodes.Count == 3) { _rightExpr = (ScriptExpr)args.ChildNodes[2]; } Debug.Assert(_oper == "=" || _oper == ":=" || _oper == "+=" || _oper == "-=" || _oper == "++" || _oper == "--" || _oper == ":="); switch (_oper) { case "=": _assignOperation = Assign; break; case ":=": _assignOperation = AssignEx; break; case "++": _assignOperation = PlusPlus; break; case "--": _assignOperation = MinusMinus; break; case "+=": _assignOperation = PlusEqual; break; case "-=": _assignOperation = MinusEqual; break; default: throw new System.InvalidOperationException(string.Format(Strings.AssignmentOperatorNotSupported, _oper)); } _minus = RuntimeHost.GetBinaryOperator(OperatorCodes.Sub); _plus = RuntimeHost.GetBinaryOperator(OperatorCodes.Add); if (_plus == null || _minus == null) { throw new ScriptRuntimeException(string.Format(Strings.MissingOperatorError, "+,-")); } }