aboutsummaryrefslogtreecommitdiff
path: root/src/functionast.cpp
blob: 1c79b3044d50c7ca5588c1e004e703c02298610d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
 * Copyright (C) 2007-2014 Xagasoft, All rights reserved.
 *
 * This file is part of the Xagasoft Build and is released under the
 * terms of the license contained in the file LICENSE.
 */

#include "functionast.h"
#include "astbranch.h"
#include "astleaf.h"
#include "runner.h"
#include "context.h"

#include <bu/sio.h>
using namespace Bu;

FunctionAst::FunctionAst( const AstBranch *pRoot, class Runner *pRunner ) :
    pRoot( pRoot ),
    pRunner( pRunner )
{
    sName = dynamic_cast<AstLeaf *>(
        *(*pRoot->getBranchBegin()).begin()
        )->getStrValue();
}

FunctionAst::~FunctionAst()
{
}

Bu::String FunctionAst::getName() const
{
    return sName;
}

Variable FunctionAst::call( Variable &input, VarList lParams )
{
    pContext->pushScope();
    
    AstBranch::NodeList::const_iterator vName = 
        (*(pRoot->getBranchBegin()+1)).begin();
    VarList::iterator vValue = lParams.begin();
    for( ; vName && vValue; vName++, vValue++ )
    {
        pContext->addVariable(
            dynamic_cast<const AstLeaf *>(*vName)->getStrValue(),
            *vValue
            );
    }
    pContext->addVariable("INPUT", input );
    Variable vRet = pRunner->run( (*(pRoot->getBranchBegin()+2)).begin() );
    pContext->popScope();
    return vRet;
}