#region License Information /* HeuristicLab * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using Irony.Ast; using Irony.Interpreter; using Irony.Interpreter.Ast; using Irony.Parsing; namespace HeuristicLab.BenchmarkGenerator { public class FunctionCallNode : AstNode { private AstNode targetRef; private string targetName; private AstNode arguments; public object Result { get; private set; } public override void Init(AstContext context, ParseTreeNode treeNode) { base.Init(context, treeNode); var nodes = treeNode.GetMappedChildNodes(); targetRef = AddChild("Target", nodes[0]); targetRef.UseType = NodeUseType.CallTarget; targetName = nodes[0].FindTokenAndGetText(); arguments = AddChild("Args", nodes[1]); AsString = "Call " + targetName; } protected override object DoEvaluate(ScriptThread thread) { thread.CurrentNode = this; var target = targetRef.Evaluate(thread); var iCall = target as ICallTarget; if (iCall == null) thread.ThrowScriptError("Error: ", targetName); var args = (object[])arguments.Evaluate(thread); object result = iCall.Call(thread, args); thread.CurrentNode = Parent; Result = result; return result; } } }