1 /*
2  *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  *  Copyright (C) 2014 - Scilab Enterprises - Calixte DENIZET
4  *
5  * Copyright (C) 2012 - 2016 - Scilab Enterprises
6  *
7  * This file is hereby licensed under the terms of the GNU GPL v2.0,
8  * pursuant to article 5.3.4 of the CeCILL v.2.1.
9  * This file was originally licensed under the terms of the CeCILL v2.1,
10  * and continues to be available under such terms.
11  * For more information, see the COPYING file which you should have received
12  * along with this program.
13  *
14  */
15 
16 #include "data/MacroDef.hxx"
17 #include "data/GlobalsCollector.hxx"
18 
19 namespace analysis
20 {
ExistingMacroDef(types::Macro & _macro)21 ExistingMacroDef::ExistingMacroDef(types::Macro & _macro) : MacroDef(_macro.getOutputs()->size(), _macro.getInputs()->size(), _macro.getBody()), name(_macro.getName()), inputs(MacroDef::asVector(_macro.getInputs())), outputs(MacroDef::asVector(_macro.getOutputs()))
22 {
23     GlobalsCollector::collect(*this);
24 }
25 
ExistingMacroDef(const ExistingMacroDef & emd)26 ExistingMacroDef::ExistingMacroDef(const ExistingMacroDef & emd) : MacroDef(emd.inputs.size(), emd.outputs.size(), emd.original), name(emd.name), inputs(emd.inputs), outputs(emd.outputs)
27 {
28     GlobalsCollector::collect(*this);
29 }
30 
getBody()31 ast::SeqExp & ExistingMacroDef::getBody()
32 {
33     return *static_cast<ast::SeqExp *>(original)->clone();
34 }
35 
getOriginalBody()36 const ast::SeqExp & ExistingMacroDef::getOriginalBody()
37 {
38     return *static_cast<ast::SeqExp *>(original);
39 }
40 
getName()41 const std::wstring & ExistingMacroDef::getName()
42 {
43     return name;
44 }
45 
getIn()46 std::vector<symbol::Symbol> ExistingMacroDef::getIn()
47 {
48     return inputs;
49 }
50 
getOut()51 std::vector<symbol::Symbol> ExistingMacroDef::getOut()
52 {
53     return outputs;
54 }
55 
clone() const56 MacroDef * ExistingMacroDef::clone() const
57 {
58     return new ExistingMacroDef(*this);
59 }
60 
DeclaredMacroDef(ast::FunctionDec * const _dec)61 DeclaredMacroDef::DeclaredMacroDef(ast::FunctionDec * const _dec) : MacroDef(_dec->getReturns().getVars().size(), _dec->getArgs().getVars().size(), _dec)
62 {
63     GlobalsCollector::collect(*this);
64 }
65 
getBody()66 ast::SeqExp & DeclaredMacroDef::getBody()
67 {
68     return *static_cast<ast::SeqExp *>(static_cast<ast::FunctionDec *>(original)->getBody().clone());
69 }
70 
getOriginalBody()71 const ast::SeqExp & DeclaredMacroDef::getOriginalBody()
72 {
73     return static_cast<ast::SeqExp &>(static_cast<ast::FunctionDec *>(original)->getBody());
74 }
75 
getName()76 const std::wstring & DeclaredMacroDef::getName()
77 {
78     return static_cast<ast::FunctionDec *>(original)->getSymbol().getName();
79 }
80 
getIn()81 std::vector<symbol::Symbol> DeclaredMacroDef::getIn()
82 {
83     return MacroDef::asVector(&static_cast<ast::FunctionDec *>(original)->getArgs().getVars());
84 }
85 
getOut()86 std::vector<symbol::Symbol> DeclaredMacroDef::getOut()
87 {
88     return MacroDef::asVector(&static_cast<ast::FunctionDec *>(original)->getReturns().getVars());
89 }
90 
clone() const91 MacroDef * DeclaredMacroDef::clone() const
92 {
93     return new DeclaredMacroDef(static_cast<ast::FunctionDec *>(original));
94 }
95 
96 } // namespace analysis
97