aboutsummaryrefslogtreecommitdiff
path: root/src/action.cpp
blob: 74d7b8c3feef7c5db7bedd05e38396ebd9114708 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
 * 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 "action.h"
#include "ast.h"
#include "astbranch.h"
#include "astleaf.h"
#include "runner.h"
#include "variable.h"

Action::Action( const class AstBranch *pRoot ) :
    pRoot( pRoot ),
    pAst( NULL )
{
    sName = dynamic_cast<AstLeaf *>(
        *(*pRoot->getBranchBegin()).begin()
        )->getStrValue();
}

Action::~Action()
{
    delete pAst;
    pAst = NULL;
}

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

void Action::call( class Runner *pRunner )
{
    pRunner->run( (*(pRoot->getBranchBegin()+1)).begin() );
}

Action *Action::genDefaultAll()
{
    Ast *pAst = new Ast();
    pAst->addNode( AstNode::typeActionDef );
        pAst->openBranch();
            pAst->addNode( AstNode::typeString, "all" );
        pAst->openBranch();
            pAst->addNode( AstNode::typeProcessTarget );
                pAst->openBranch();
                    pAst->addNode( AstNode::typeString, "build" );
                pAst->openBranch();
                    pAst->addNode( AstNode::typeFunction );
                        pAst->openBranch();
                            pAst->addNode( AstNode::typeString, "targets" );
                    pAst->closeNode();
            pAst->closeNode();
    pAst->closeNode();
    Action *pRet = new Action(
        dynamic_cast<const AstBranch *>( *pAst->getNodeBegin() )
        );
    pRet->pAst = pAst;

    return pRet;
}

Action *Action::genDefaultClean()
{
    Ast *pAst = new Ast();
    pAst->addNode( AstNode::typeActionDef );
        pAst->openBranch();
            pAst->addNode( AstNode::typeString, "clean" );
        pAst->openBranch();
            pAst->addNode( AstNode::typeProcessTarget );
                pAst->openBranch();
                    pAst->addNode( AstNode::typeString, "clean" );
                pAst->openBranch();
                    pAst->addNode( AstNode::typeFunction );
                        pAst->openBranch();
                            pAst->addNode( AstNode::typeString, "targets" );
                    pAst->closeNode();
            pAst->closeNode();
    pAst->closeNode();
    Action *pRet = new Action(
        dynamic_cast<const AstBranch *>( *pAst->getNodeBegin() )
        );
    pRet->pAst = pAst;

    return pRet;
}

Action *Action::genDefaultCleanAll()
{
    Ast *pAst = new Ast();
    pAst->addNode( AstNode::typeActionDef );
        pAst->openBranch();
            pAst->addNode( AstNode::typeString, "clean-all" );
        pAst->openBranch();
            pAst->addNode( AstNode::typeProcessTarget );
                pAst->openBranch();
                    pAst->addNode( AstNode::typeString, "clean" );
                pAst->openBranch();
                    pAst->addNode( AstNode::typeFunction );
                        pAst->openBranch();
                            pAst->addNode( AstNode::typeString, "targets" );
                    pAst->closeNode();
            pAst->closeNode();
    pAst->closeNode();
    Action *pRet = new Action(
        dynamic_cast<const AstBranch *>( *pAst->getNodeBegin() )
        );
    pRet->pAst = pAst;

    return pRet;
}

Action *Action::genDefaultDefault()
{
    Ast *pAst = new Ast();
    pAst->addNode( AstNode::typeActionDef );
        pAst->openBranch();
            pAst->addNode( AstNode::typeString, "default" );
        pAst->openBranch();
            pAst->addNode( AstNode::typeProcessTarget );
                pAst->openBranch();
                    pAst->addNode( AstNode::typeString, "build" );
                pAst->openBranch();
                    pAst->addNode( AstNode::typeFunction );
                        pAst->openBranch();
                            pAst->addNode( AstNode::typeString, "targets" );
                    pAst->closeNode();
            pAst->closeNode();
    pAst->closeNode();
    Action *pRet = new Action(
        dynamic_cast<const AstBranch *>( *pAst->getNodeBegin() )
        );
    pRet->pAst = pAst;

    return pRet;
}