2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2014 - Scilab Enterprises - Calixte DENIZET
5 * Copyright (C) 2012 - 2016 - Scilab Enterprises
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.
16 #include "AnalysisVisitor.hxx"
17 #include "analyzers/SizeAnalyzer.hxx"
18 #include "call/SizeCall.hxx"
24 bool SizeAnalyzer::analyze(AnalysisVisitor & visitor, const unsigned int lhs, ast::CallExp & e)
31 const ast::exps_t args = e.getArgs();
34 ROWS, COLS, ROWSTIMESCOLS, ROWSCOLS, ONE, BOTH, DUNNO
36 const std::size_t size = args.size();
37 if (size == 0 || size >= 3)
42 ast::Exp * first = *args.begin();
47 first->accept(visitor);
48 Result & res = visitor.getResult();
49 if (!res.getType().ismatrix())
51 visitor.getDM().releaseTmp(res.getTempId(), first);
69 ast::Exp * second = *std::next(args.begin());
70 if (second && lhs == 1)
72 if (second->isStringExp())
74 const std::wstring & arg2 = static_cast<ast::StringExp *>(second)->getValue();
79 else if (arg2 == L"c")
83 else if (arg2 == L"*")
89 visitor.getDM().releaseTmp(res.getTempId(), first);
93 else if (second->isDoubleExp())
95 const double arg2 = static_cast<ast::DoubleExp *>(second)->getValue();
106 // TODO: we should handle hypermatrix
111 visitor.getDM().releaseTmp(res.getTempId(), first);
118 visitor.getDM().releaseTmp(res.getTempId(), first);
124 visitor.getDM().releaseTmp(res.getTempId(), first);
128 TIType type(visitor.getGVN(), TIType::DOUBLE);
134 SymbolicDimension & rows = res.getType().rows;
135 Result & _res = e.getDecorator().setResult(type);
136 _res.getConstant() = rows.getValue();
137 e.getDecorator().setCall(new SizeCall(SizeCall::R));
138 visitor.setResult(_res);
143 SymbolicDimension & cols = res.getType().cols;
144 Result & _res = e.getDecorator().setResult(type);
145 _res.getConstant() = cols.getValue();
146 e.getDecorator().setCall(new SizeCall(SizeCall::C));
147 visitor.setResult(_res);
152 SymbolicDimension & rows = res.getType().rows;
153 SymbolicDimension & cols = res.getType().cols;
154 SymbolicDimension prod = rows * cols;
155 Result & _res = e.getDecorator().setResult(type);
156 _res.getConstant() = prod.getValue();
157 e.getDecorator().setCall(new SizeCall(SizeCall::RC));
158 visitor.setResult(_res);
163 SymbolicDimension & rows = res.getType().rows;
164 SymbolicDimension & cols = res.getType().cols;
165 std::vector<Result> & mlhs = visitor.getLHSContainer();
168 mlhs.emplace_back(type);
169 mlhs.back().getConstant() = rows.getValue();
170 mlhs.emplace_back(type);
171 mlhs.back().getConstant() = cols.getValue();
173 e.getDecorator().setCall(new SizeCall(SizeCall::R_C));
178 Result & _res = e.getDecorator().setResult(type);
179 _res.getConstant() = new types::Double(1);
180 e.getDecorator().setCall(new SizeCall(SizeCall::ONE));
181 visitor.setResult(_res);
186 TIType _type(visitor.getGVN(), TIType::DOUBLE, 1, 2);
187 Result & _res = e.getDecorator().setResult(_type);
188 e.getDecorator().setCall(new SizeCall(SizeCall::BOTH));
189 visitor.setResult(_res);