private void AssignArray(object value, IScriptContext context) { object obj = context.GetItem(Identifier, true); foreach (ScriptAst node in Modifiers) { ScriptFunctionCall functionCall = node as ScriptFunctionCall; if (functionCall != null) { obj = CallFunction(context.GetFunctionDefinition(Identifier), functionCall, context); continue; } ScriptArrayResolution arrayResolution = node as ScriptArrayResolution; if (arrayResolution != null) { SetArrayValue(obj, arrayResolution, context, value); continue; } ScriptGenericsPostfix genericPostfix = node as ScriptGenericsPostfix; if (genericPostfix != null) { throw new NotSupportedException(); } } }
private void EvaluateFunctionCall(IScriptContext context) { EvaluateIdentifier(context); foreach (ScriptAst node in Modifiers) { ScriptFunctionCall funcCall = node as ScriptFunctionCall; if (funcCall != null) { IInvokable function = context.Result as IInvokable; if (function == null) { throw new ScriptException("Is not a function type"); } context.Result = CallFunction(function, funcCall, context); continue; } ScriptArrayResolution arrayResolution = node as ScriptArrayResolution; if (arrayResolution != null) { GetArrayValue(context.Result, arrayResolution, context); continue; } ScriptGenericsPostfix genericPostfix = node as ScriptGenericsPostfix; if (genericPostfix != null) { throw new NotSupportedException(); //genericPostfix.Evaluate(Context); //continue; } } }
public ScriptQualifiedName(AstNodeArgs args) : base(args) { if (ChildNodes.Count == 2 && ChildNodes[1].ChildNodes.Count == 0) { Identifier = ((Token)ChildNodes[0]).Text; evaluation = EvaluateIdentifier; assignment = AssignIdentifier; } else if (ChildNodes[0] is Token && ChildNodes[1].ChildNodes.Count != 0) { Identifier = (ChildNodes[0] as Token).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); } ScriptGenericsPostfix 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 = ((Token)ChildNodes[2]).Text; 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; } }
private void EvaluateGenericType(IScriptContext context) { ScriptGenericsPostfix genericPostfix = (ScriptGenericsPostfix)Modifiers.First(); Type genericType = GetIndentifierValue(context, genericPostfix.GetGenericTypeName(Identifier)) as Type; if (genericType == null || !genericType.IsGenericType) { throw new ScriptException("Given type is not generic"); } genericPostfix.Evaluate(context); context.Result = genericType.MakeGenericType((Type[])context.Result); }
private void EvaluateNamePart(IScriptContext context) { NamePart.Evaluate(context); object obj = context.Result; if (Modifiers == null) { context.Result = GetMemberValue(obj, Identifier); return; } Type[] genericArguments = null; foreach (ScriptAst node in Modifiers) { //NOTE: Generic modifier should be the first among other modifiers in the list ScriptGenericsPostfix generic = node as ScriptGenericsPostfix; if (generic != null) { if (genericArguments != null) { throw new ScriptException("Wrong modifiers sequence"); } generic.Execute(context); genericArguments = (Type[])context.Result; continue; } ScriptFunctionCall functionCall = node as ScriptFunctionCall; if (functionCall != null) { CallClassMethod(obj, Identifier, functionCall, genericArguments, context); continue; } ScriptArrayResolution arrayResolution = node as ScriptArrayResolution; if (arrayResolution != null) { GetArrayValue(GetMemberValue(obj, Identifier), arrayResolution, context); continue; } } }
public ScriptTypeExpr(AstNodeArgs args) : base(args) { if (ChildNodes.Count == 2 && ChildNodes[1].ChildNodes.Count == 0) { Identifier = ((Token)ChildNodes[0]).Text; } else if (ChildNodes[0] is ScriptTypeExpr) { TypeExpr = ChildNodes[0] as ScriptTypeExpr; Identifier = (ChildNodes[2].ChildNodes[0] as Token).Text; GenericsPostfix = ChildNodes[2].ChildNodes[1] as ScriptGenericsPostfix; } else { GenericsPostfix = (ScriptGenericsPostfix)ChildNodes[1]; Identifier = GenericsPostfix.GetGenericTypeName(((Token)ChildNodes[0]).Text); } }