Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Benchmark Generator/HeuristicLab.BenchmarkGenerator/3.3/FunctionCallNode.cs @ 11571

Last change on this file since 11571 was 10088, checked in by bburlacu, 11 years ago

#2083: Removed old project and rewritten the Benchmark Generator as a HeuristicLab plugin. Added new functions and visualization capability.

File size: 2.0 KB
RevLine 
[10088]1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using Irony.Ast;
23using Irony.Interpreter;
24using Irony.Interpreter.Ast;
25using Irony.Parsing;
26
27namespace HeuristicLab.BenchmarkGenerator {
28  public class FunctionCallNode : AstNode {
29    private AstNode targetRef;
30    private string targetName;
31    private AstNode arguments;
32
33    public object Result { get; private set; }
34
35    public override void Init(AstContext context, ParseTreeNode treeNode) {
36      base.Init(context, treeNode);
37      var nodes = treeNode.GetMappedChildNodes();
38      targetRef = AddChild("Target", nodes[0]);
39      targetRef.UseType = NodeUseType.CallTarget;
40      targetName = nodes[0].FindTokenAndGetText();
41      arguments = AddChild("Args", nodes[1]);
42      AsString = "Call " + targetName;
43    }
44
45    protected override object DoEvaluate(ScriptThread thread) {
46      thread.CurrentNode = this;
47      var target = targetRef.Evaluate(thread);
48      var iCall = target as ICallTarget;
49      if (iCall == null)
50        thread.ThrowScriptError("Error: ", targetName);
51      var args = (object[])arguments.Evaluate(thread);
52      object result = iCall.Call(thread, args);
53      thread.CurrentNode = Parent;
54      Result = result;
55      return result;
56    }
57  }
58}
Note: See TracBrowser for help on using the repository browser.