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 #ifndef __RESULT_HXX__
17 #define __RESULT_HXX__
18 
19 #include <iostream>
20 
21 #include "gvn/GVN.hxx"
22 #include "gvn/SymbolicDimension.hxx"
23 #include "gvn/SymbolicRange.hxx"
24 #include "TIType.hxx"
25 #include "tools.hxx"
26 #include "ConstantValue.hxx"
27 
28 namespace analysis
29 {
30 class Result
31 {
32 
33 public:
34 
35     enum FnName { ZEROS, ONES, RAND, DUNNO };
36 
37 private:
38 
39     TIType type;
40     int tempId;
41     uint64_t functionId;
42     FnName fnname;
43     ConstantValue constant;
44     SymbolicRange range;
45     SymbolicDimension maxIndex;
46 
47 public:
48 
Result()49     Result() : type(), tempId(-1), functionId(0), fnname(DUNNO), constant(), range(), maxIndex() { }
Result(const TIType & _type,const int _tempId=-1,const uint64_t _functionId=0)50     Result(const TIType & _type, const int _tempId = -1, const uint64_t _functionId = 0) : type(_type), tempId(_tempId), functionId(_functionId), fnname(DUNNO), constant(), range(), maxIndex() { }
Result(TIType && _type,const int _tempId=-1,const uint64_t _functionId=0)51     Result(TIType && _type, const int _tempId = -1, const uint64_t _functionId = 0) : type(_type), tempId(_tempId), functionId(_functionId), fnname(DUNNO), constant(), range(), maxIndex() { }
52 
istemp() const53     inline bool istemp() const
54     {
55         return tempId >= 0;
56     }
57 
setFnName(FnName _fnname)58     inline void setFnName(FnName _fnname)
59     {
60         fnname = _fnname;
61     }
62 
getFnName() const63     inline FnName getFnName() const
64     {
65         return fnname;
66     }
67 
getType() const68     inline const TIType & getType() const
69     {
70         return type;
71     }
72 
getType()73     inline TIType & getType()
74     {
75         return type;
76     }
77 
getTempId() const78     inline int getTempId() const
79     {
80         return tempId;
81     }
82 
isTemp() const83     inline bool isTemp() const
84     {
85         return tempId != -1;
86     }
87 
setFunctionId(const uint64_t id)88     inline void setFunctionId(const uint64_t id)
89     {
90         functionId = id;
91     }
92 
getFunctionId() const93     inline uint64_t getFunctionId() const
94     {
95         return functionId;
96     }
97 
hasGVNValue() const98     inline bool hasGVNValue() const
99     {
100         return constant.getGVNValue() != nullptr;
101     }
102 
getConstant()103     inline ConstantValue & getConstant()
104     {
105         return constant;
106     }
107 
getConstant() const108     inline const ConstantValue & getConstant() const
109     {
110         return constant;
111     }
112 
setConstant(ConstantValue & val)113     inline ConstantValue & setConstant(ConstantValue & val)
114     {
115         constant = val;
116         return constant;
117     }
118 
getRange()119     inline SymbolicRange & getRange()
120     {
121         return range;
122     }
123 
getRange() const124     inline const SymbolicRange & getRange() const
125     {
126         return range;
127     }
128 
setRange(SymbolicRange & _range)129     inline SymbolicRange & setRange(SymbolicRange & _range)
130     {
131         range = _range;
132         return range;
133     }
134 
setRange(SymbolicRange && _range)135     inline SymbolicRange & setRange(SymbolicRange && _range)
136     {
137         range = _range;
138         return range;
139     }
140 
isAnInt() const141     inline bool isAnInt() const
142     {
143         return hasGVNValue() || getRange().isValid();
144     }
145 
getMaxIndex()146     inline SymbolicDimension & getMaxIndex()
147     {
148         return maxIndex;
149     }
150 
getMaxIndex() const151     inline const SymbolicDimension & getMaxIndex() const
152     {
153         return maxIndex;
154     }
155 
setMaxIndex(SymbolicDimension & _maxIndex)156     inline SymbolicDimension & setMaxIndex(SymbolicDimension & _maxIndex)
157     {
158         maxIndex = _maxIndex;
159         return maxIndex;
160     }
161 
setMaxIndex(SymbolicDimension && _maxIndex)162     inline SymbolicDimension & setMaxIndex(SymbolicDimension && _maxIndex)
163     {
164         maxIndex = _maxIndex;
165         return maxIndex;
166     }
167 
operator <<(std::wostream & out,const Result & res)168     friend std::wostream & operator<<(std::wostream & out, const Result & res)
169     {
170         out << L"Result {" << res.type;
171         if (res.tempId != -1)
172         {
173             out << L", temp id:" << res.tempId;
174         }
175         if (res.functionId)
176         {
177             out << L", function id:" << res.functionId;
178         }
179         if (res.constant.isKnown())
180         {
181             out << L", constant:" << res.constant;
182         }
183         if (res.isAnInt())
184         {
185             out << L", isAnInt: T";
186         }
187         out << L'}';
188 
189         return out;
190     }
191 };
192 
193 } // namespace analysis
194 
195 #endif // __RESULT_HXX__
196