package traci.lang.interpreter.node;

import java.util.ArrayList;
import java.util.List;

import traci.lang.interpreter.Context;
import traci.lang.interpreter.Entities;
import traci.lang.interpreter.Entities.Entity;
import traci.lang.interpreter.Function;
import traci.lang.interpreter.FunctionReturnException;
import traci.lang.interpreter.TraciValue;

public class FunctionCallNode implements TraciNode
{
    private final String id;
    private final List<TraciNode> argNodes;
    private final BlockNode blockNode;

    public FunctionCallNode(final String id, final List<TraciNode> argNodes, final BlockNode blockNode)
    {
        this.id = id;
        this.argNodes = argNodes;
        this.blockNode = blockNode;
    }

    @Override
    public TraciValue eval(final Context context) throws FunctionReturnException
    {
        final Function functionNode = context.getFunction(id);
        final List<TraciValue> args = new ArrayList<TraciValue>();

        for (final TraciNode argNode : argNodes)
        {
            args.add(argNode.eval(context));
        }

        TraciValue value = functionNode.invoke(context, args);

        if (blockNode != null)
        {
            final Entity entity = Entities.makeEntity(value.getObject());
            blockNode.eval(context.newEntity(entity));
            value = entity.getValue();
        }

        return value;
    }
}

@@ -345,16 +345,39 @@
 ciValue;
+%0Aimport traci.util.Log;
 %0A%0Apublic
@@ -973,24 +973,144 @@
 iValue%3E();%0A%0A
+        if (functionNode == null)%0A        %7B%0A            Log.ERROR(%22No such function defined: '%22 + id + %22'%22);%0A        %7D%0A%0A
         for 

Print error.