/usr/include/scilab/AnalysisVisitor.hxx is in scilab-include 6.0.1-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 | /*
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
* Copyright (C) 2014 - Scilab Enterprises - Calixte DENIZET
*
* Copyright (C) 2012 - 2016 - Scilab Enterprises
*
* This file is hereby licensed under the terms of the GNU GPL v2.0,
* pursuant to article 5.3.4 of the CeCILL v.2.1.
* This file was originally licensed under the terms of the CeCILL v2.1,
* and continues to be available under such terms.
* For more information, see the COPYING file which you should have received
* along with this program.
*
*/
#ifndef __ANALYSIS_VISITOR_HXX__
#define __ANALYSIS_VISITOR_HXX__
#include <algorithm>
#include <limits>
#include <map>
#include <memory>
#include <stack>
#include <vector>
#include "visitor.hxx"
#include "prettyprintvisitor.hxx"
#include "execvisitor.hxx"
#include "printvisitor.hxx"
#include "allexp.hxx"
#include "allvar.hxx"
#include "analyzers/CallAnalyzer.hxx"
#include "checkers/Checkers.hxx"
#include "Chrono.hxx"
#include "DollarInfo.hxx"
#include "ForList.hxx"
#include "Result.hxx"
#include "TIType.hxx"
#include "ConstantVisitor.hxx"
#include "gvn/SymbolicList.hxx"
#include "FBlockEmittedListener.hxx"
#include "data/DataManager.hxx"
#include "data/PolymorphicMacroCache.hxx"
#include "gvn/ConstraintManager.hxx"
#include "logging/Logger.hxx"
#include "dynlib_ast.h"
namespace analysis
{
class EXTERN_AST AnalysisVisitor : public ast::Visitor, public Chrono
{
public:
typedef std::unordered_map<std::wstring, std::shared_ptr<CallAnalyzer>> MapSymCall;
private:
Result _result;
DataManager dm;
PolymorphicMacroCache pmc;
ConstraintManager cm;
ConstantVisitor cv;
ast::PrettyPrintVisitor dv;
ast::PrintVisitor pv;
std::vector<Result> multipleLHS;
logging::Logger logger;
std::vector<FBlockEmittedListener *> fblockListeners;
std::stack<ast::Exp *> loops;
std::stack<DollarInfo> argIndices;
static MapSymCall symscall;
static MapSymCall initCalls();
public:
static bool asDouble(ast::Exp & e, double & out);
static bool asDouble(types::InternalType * pIT, double & out);
static bool isDoubleConstant(const ast::Exp & e);
static bool asDoubleMatrix(ast::Exp & e, types::Double *& data);
static void analyze(ast::SelectExp & e);
AnalysisVisitor();
virtual ~AnalysisVisitor();
virtual AnalysisVisitor* clone()
{
return new AnalysisVisitor();
}
inline CallAnalyzer * getAnalyzer(const symbol::Symbol & sym)
{
MapSymCall::iterator it = symscall.find(sym.getName());
if (it == symscall.end())
{
return nullptr;
}
else
{
return it->second.get();
}
}
inline DataManager & getDM()
{
return dm;
}
inline GVN & getGVN()
{
return dm.getGVN();
}
inline PolymorphicMacroCache & getPMC()
{
return pmc;
}
inline ConstantVisitor & getCV()
{
return cv;
}
inline ast::PrintVisitor & getPV()
{
return pv;
}
inline ast::PrettyPrintVisitor & getDV()
{
return dv;
}
inline ast::ExecVisitor & getExec()
{
return cv.getExec();
}
inline void finalize()
{
//dm.finalize(nullptr);
}
inline void setResult(Result & val)
{
_result = val;
}
inline void setResult(Result && val)
{
_result = val;
}
inline Result & getResult()
{
return _result;
}
inline std::vector<Result> & getLHSContainer()
{
return multipleLHS;
}
inline ConstraintManager & getCM()
{
if (FunctionBlock * fblock = getDM().topFunction())
{
return fblock->getConstraintManager();
}
else
{
return cm;
}
}
inline ast::Exp * getCurrentLoop() const
{
if (!loops.empty())
{
return loops.top();
}
return nullptr;
}
inline void registerFBlockEmittedListener(FBlockEmittedListener * listener)
{
if (listener)
{
fblockListeners.push_back(listener);
}
}
inline void emitFunctionBlock(FunctionBlock & fblock)
{
for (auto listener : fblockListeners)
{
listener->action(fblock);
}
}
inline Info & getSymInfo(const symbol::Symbol & sym)
{
return dm.getInfo(sym);
}
void reset();
bool analyzeIndices(TIType & type, ast::CallExp & ce);
// Only for debug use
void print_info();
logging::Logger & getLogger();
private:
bool getDimension(SymbolicDimension & dim, ast::Exp & arg, bool & safe, SymbolicDimension & out);
/*
Workaround for a C++11 bug with Intel compiler
https://software.intel.com/fr-fr/forums/topic/514793
*/
inline static TIType _check_plus(GVN & gvn, const TIType & Ltype, const TIType & Rtype)
{
return Checkers::check_____add____(gvn, Ltype, Rtype);
}
inline static TIType _check_minus(GVN & gvn, const TIType & Ltype, const TIType & Rtype)
{
return Checkers::check_____sub____(gvn, Ltype, Rtype);
}
inline static TIType _check_dottimes(GVN & gvn, const TIType & Ltype, const TIType & Rtype)
{
return Checkers::check_____dottimes____(gvn, Ltype, Rtype);
}
inline static TIType _check_dotrdiv(GVN & gvn, const TIType & Ltype, const TIType & Rtype)
{
return Checkers::check_____dotrdiv____(gvn, Ltype, Rtype);
}
inline static TIType _check_dotpower(GVN & gvn, const TIType & Ltype, const TIType & Rtype)
{
return Checkers::check_____dotpower____(gvn, Ltype, Rtype);
}
inline static TIType _check_eq(GVN & gvn, const TIType & Ltype, const TIType & Rtype)
{
return Checkers::check_____eq____(gvn, Ltype, Rtype);
}
inline static TIType _check_neq(GVN & gvn, const TIType & Ltype, const TIType & Rtype)
{
return Checkers::check_____neq____(gvn, Ltype, Rtype);
}
inline static TIType _check_lt(GVN & gvn, const TIType & Ltype, const TIType & Rtype)
{
return Checkers::check_____lt____(gvn, Ltype, Rtype);
}
inline static TIType _check_le(GVN & gvn, const TIType & Ltype, const TIType & Rtype)
{
return Checkers::check_____le____(gvn, Ltype, Rtype);
}
inline static TIType _check_gt(GVN & gvn, const TIType & Ltype, const TIType & Rtype)
{
return Checkers::check_____gt____(gvn, Ltype, Rtype);
}
inline static TIType _check_ge(GVN & gvn, const TIType & Ltype, const TIType & Rtype)
{
return Checkers::check_____ge____(gvn, Ltype, Rtype);
}
inline static TIType _check_and(GVN & gvn, const TIType & Ltype, const TIType & Rtype)
{
return Checkers::check_____and____(gvn, Ltype, Rtype);
}
inline static TIType _check_or(GVN & gvn, const TIType & Ltype, const TIType & Rtype)
{
return Checkers::check_____or____(gvn, Ltype, Rtype);
}
inline static TIType _check_andand(GVN & gvn, const TIType & Ltype, const TIType & Rtype)
{
return Checkers::check_____and____(gvn, Ltype, Rtype);
}
inline static TIType _check_oror(GVN & gvn, const TIType & Ltype, const TIType & Rtype)
{
return Checkers::check_____or____(gvn, Ltype, Rtype);
}
template<TIType (F)(GVN &, const TIType &, const TIType &)>
inline TIType checkEWBinOp(TIType & LT, TIType & RT, const Result & LR, const Result & RR, bool & safe, int & tempId, ast::Exp * Lexp, ast::Exp * Rexp)
{
TIType resT = F(getGVN(), LT, RT);
if (resT.hasInvalidDims())
{
const bool ret = getCM().check(ConstraintManager::SAMEDIMS, LT.rows.getValue(), LT.cols.getValue(), RT.rows.getValue(), RT.cols.getValue());
if (ret)
{
resT = F(getGVN(), LT, RT);
safe = true;
}
else
{
resT = resT.asUnknownMatrix();
}
}
else
{
safe = true;
}
tempId = getTmpIdForEWOp(resT, LR, RR, Lexp, Rexp);
if (resT.isscalar())
{
// TODO
}
return resT;
}
bool operGVNValues(ast::OpExp & oe);
bool operSymbolicRange(ast::OpExp & oe);
// get temp id for an element-wise operation
// A + (B + 1) => B+1 is a temp, A is not and we can reuse the temp to put the result of A + (B+1)
int getTmpIdForEWOp(const TIType & resT, const Result & LR, const Result & RR, ast::Exp * Lexp, ast::Exp * Rexp);
void visitArguments(const std::wstring & name, const unsigned int lhs, const TIType & calltype, ast::CallExp & e, const ast::exps_t & args);
void visit(ast::SelectExp & e);
void visit(ast::ListExp & e);
void visitInVarDecCtxt(ast::ListExp & e);
void visit(ast::MatrixExp & e);
void visit(ast::OpExp & e);
void visit(ast::NotExp & e);
void visit(ast::TransposeExp & e);
void visit(ast::AssignExp & e);
void visit(ast::IfExp & e);
void visit(ast::ForExp & e);
void visit(ast::CallExp & e);
void visit(ast::CallExp & e, const unsigned int lhs);
void visit(ast::SeqExp & e);
void visit(ast::DoubleExp & e);
void visit(ast::BoolExp & e);
void visit(ast::StringExp & e);
void visit(ast::SimpleVar & e);
void visit(ast::DollarVar & e);
void visit(ast::VarDec & e);
void visit(ast::MatrixLineExp & e)
{
/* treated in MatrixExp */
}
void visit(ast::OptimizedExp & e) { }
void visit(ast::MemfillExp & e) { }
void visit(ast::DAXPYExp & e) { }
void visit(ast::IntSelectExp & e) { }
void visit(ast::StringSelectExp & e) { }
void visit(ast::CommentExp & e) { }
void visit(ast::NilExp & e) { }
void visit(ast::ColonVar & e) { }
void visit(ast::WhileExp & e);
void visit(ast::ArrayListVar & e)
{
logger.log(L"ArrayListVar", e.getLocation());
const ast::exps_t & vars = e.getVars();
for (auto var : vars)
{
var->accept(*this);
}
}
void visit(ast::CellCallExp & e)
{
logger.log(L"CellCallExp", e.getLocation());
visit(static_cast<ast::CallExp &>(e));
}
void visit(ast::LogicalOpExp & e)
{
logger.log(L"LogicalOpExp", e.getLocation());
visit(static_cast<ast::OpExp &>(e));
}
void visit(ast::BreakExp & e)
{
logger.log(L"BreakExp", e.getLocation());
// nothing to do
}
void visit(ast::ContinueExp & e)
{
logger.log(L"ContinueExp", e.getLocation());
// nothing to do
}
void visit(ast::TryCatchExp & e)
{
logger.log(L"TryCatchExp", e.getLocation());
e.getTry().accept(*this);
e.getCatch().accept(*this);
}
void visit(ast::CaseExp & e)
{
logger.log(L"CaseExp", e.getLocation());
e.getTest()->accept(*this);
e.getBody()->accept(*this);
}
void visit(ast::ReturnExp & e)
{
logger.log(L"ReturnExp", e.getLocation());
getDM().getCurrent()->setReturn(true);
// Bug with return;
//e.exp_get().accept(*this);
}
void visit(ast::FieldExp & e)
{
logger.log(L"FieldExp", e.getLocation());
// a.b.c <=> (a.b).c where a.b is the head and c is the tail
//e.head_get()->accept(*this);
//e.tail_get()->accept(*this);
}
void visit(ast::CellExp & e)
{
logger.log(L"CellExp", e.getLocation());
visit(static_cast<ast::MatrixExp &>(e));
}
void visit(ast::ArrayListExp & e)
{
logger.log(L"ArrayListExp", e.getLocation());
for (const auto exp : e.getExps())
{
exp->accept(*this);
}
}
void visit(ast::AssignListExp & e)
{
logger.log(L"AssignListExp", e.getLocation());
visit(static_cast<ast::ArrayListExp &>(e));
}
void visit(ast::FunctionDec & e)
{
/*e.args_get().accept(*this);
e.returns_get().accept(*this);
e.body_get().accept(*this);*/
logger.log(L"FunctionDec", e.getLocation());
dm.macrodef(&e);
}
};
} // namespace analysis
#endif // __ANALYSIS_VISITOR_HXX__
|