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 |
|
---|
22 | using Irony.Ast;
|
---|
23 | using Irony.Interpreter;
|
---|
24 | using Irony.Interpreter.Ast;
|
---|
25 | using Irony.Parsing;
|
---|
26 |
|
---|
27 | namespace 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 | }
|
---|