Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
FunctionCallNode.cs
Go to the documentation of this file.
1 #region License
2 /* **********************************************************************************
3  * Copyright (c) Roman Ivantsov
4  * This source code is subject to terms and conditions of the MIT License
5  * for Irony. A copy of the license can be found in the License.txt file
6  * at the root of this distribution.
7  * By using this source code in any fashion, you are agreeing to be bound by the terms of the
8  * MIT License.
9  * You must not remove this notice from this software.
10  * **********************************************************************************/
11 #endregion
12 
13 using System;
14 using System.Collections.Generic;
15 using System.Linq;
16 using System.Text;
17 using Irony.Interpreter;
18 using Irony.Parsing;
19 
20 namespace Irony.Interpreter.Ast {
21 
22  //A node representing function call
23  public class FunctionCallNode : AstNode {
24  AstNode TargetRef;
25  AstNode Arguments;
26  string _targetName;
27 
28  public override void Init(ParsingContext context, ParseTreeNode treeNode) {
29  base.Init(context, treeNode);
30  TargetRef = AddChild("Target", treeNode.ChildNodes[0]);
31  _targetName = treeNode.ChildNodes[0].FindTokenAndGetText();
32  Arguments = AddChild("Args", treeNode.ChildNodes[1]);
33  AsString = "Call " + _targetName;
34  }
35 
36  public override void EvaluateNode(EvaluationContext context, AstMode mode) {
37  TargetRef.Evaluate(context, AstMode.Read);
38  var target = context.Data.Pop() as ICallTarget;
39  if (target == null)
40  context.ThrowError(Resources.ErrVarIsNotCallable, _targetName);
41  Arguments.Evaluate(context, AstMode.Read);
42  target.Call(context);
43  }
44 
45  }//class
46 
47 }//namespace
ParseTreeNodeList ChildNodes
Definition: ParseTree.cs:41
override void Init(ParsingContext context, ParseTreeNode treeNode)
override void EvaluateNode(EvaluationContext context, AstMode mode)
static string ErrVarIsNotCallable
Looks up a localized string similar to Variable {0} is not a callable function..