2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2014 - Scilab Enterprises - Calixte DENIZET
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
13 #include "AnalysisVisitor.hxx"
14 #include "analyzers/SizeAnalyzer.hxx"
15 #include "call/SizeCall.hxx"
21 bool SizeAnalyzer::analyze(AnalysisVisitor & visitor, const unsigned int lhs, ast::CallExp & e)
28 const ast::exps_t args = e.getArgs();
31 ROWS, COLS, ROWSTIMESCOLS, ROWSCOLS, ONE, BOTH, DUNNO
33 const std::size_t size = args.size();
34 if (size == 0 || size >= 3)
39 ast::Exp * first = *args.begin();
44 first->accept(visitor);
45 Result & res = visitor.getResult();
46 if (!res.getType().ismatrix())
48 visitor.getDM().releaseTmp(res.getTempId());
66 ast::Exp * second = *std::next(args.begin());
67 if (second && lhs == 1)
69 if (second->isStringExp())
71 const std::wstring & arg2 = static_cast<ast::StringExp *>(second)->getValue();
76 else if (arg2 == L"c")
80 else if (arg2 == L"*")
86 visitor.getDM().releaseTmp(res.getTempId());
90 else if (second->isDoubleExp())
92 const double arg2 = static_cast<ast::DoubleExp *>(second)->getValue();
103 // TODO: we should handle hypermatrix
108 visitor.getDM().releaseTmp(res.getTempId());
115 visitor.getDM().releaseTmp(res.getTempId());
121 visitor.getDM().releaseTmp(res.getTempId());
125 TIType type(visitor.getGVN(), TIType::DOUBLE);
131 SymbolicDimension & rows = res.getType().rows;
132 Result & _res = e.getDecorator().setResult(type);
133 _res.getConstant() = rows.getValue();
134 e.getDecorator().setCall(new SizeCall(SizeCall::R));
135 visitor.setResult(_res);
140 SymbolicDimension & cols = res.getType().cols;
141 Result & _res = e.getDecorator().setResult(type);
142 _res.getConstant() = cols.getValue();
143 e.getDecorator().setCall(new SizeCall(SizeCall::C));
144 visitor.setResult(_res);
149 SymbolicDimension & rows = res.getType().rows;
150 SymbolicDimension & cols = res.getType().cols;
151 SymbolicDimension prod = rows * cols;
152 Result & _res = e.getDecorator().setResult(type);
153 _res.getConstant() = prod.getValue();
154 e.getDecorator().setCall(new SizeCall(SizeCall::RC));
155 visitor.setResult(_res);
160 SymbolicDimension & rows = res.getType().rows;
161 SymbolicDimension & cols = res.getType().cols;
162 std::vector<Result> & mlhs = visitor.getLHSContainer();
165 mlhs.emplace_back(type);
166 mlhs.back().getConstant() = rows.getValue();
167 mlhs.emplace_back(type);
168 mlhs.back().getConstant() = cols.getValue();
170 e.getDecorator().setCall(new SizeCall(SizeCall::R_C));
175 Result & _res = e.getDecorator().setResult(type);
176 _res.getConstant() = new types::Double(1);
177 e.getDecorator().setCall(new SizeCall(SizeCall::ONE));
178 visitor.setResult(_res);
183 TIType _type(visitor.getGVN(), TIType::DOUBLE, 1, 2);
184 Result & _res = e.getDecorator().setResult(_type);
185 e.getDecorator().setCall(new SizeCall(SizeCall::BOTH));
186 visitor.setResult(_res);