16 #ifndef ONCE_FPARSER_TYPES_H_ 17 #define ONCE_FPARSER_TYPES_H_ 19 #include "../fpconfig.h" 22 #ifdef ONCE_FPARSER_H_ 63 #ifdef FP_SUPPORT_OPTIMIZER 90 #ifdef ONCE_FPARSER_H_ 102 #ifdef FUNCTIONPARSER_SUPPORT_DEBUGGING 108 inline bool okForInt()
const {
return (flags & OkForInt) != 0; }
109 inline bool complexOnly()
const {
return (flags & ComplexOnly) != 0; }
112 #ifdef FUNCTIONPARSER_SUPPORT_DEBUGGING 113 # define FP_FNAME(n) n, 120 const FuncDefinition Functions[]=
122 { FP_FNAME(
"abs") 1, FuncDefinition::OkForInt },
123 { FP_FNAME(
"acos") 1, FuncDefinition::AngleOut },
124 { FP_FNAME(
"acosh") 1, FuncDefinition::AngleOut },
125 { FP_FNAME(
"arg") 1, FuncDefinition::AngleOut | FuncDefinition::ComplexOnly },
126 { FP_FNAME(
"asin") 1, FuncDefinition::AngleOut },
127 { FP_FNAME(
"asinh") 1, FuncDefinition::AngleOut },
128 { FP_FNAME(
"atan") 1, FuncDefinition::AngleOut },
129 { FP_FNAME(
"atan2") 2, FuncDefinition::AngleOut },
130 { FP_FNAME(
"atanh") 1, 0 },
131 { FP_FNAME(
"cbrt") 1, 0 },
132 { FP_FNAME(
"ceil") 1, 0 },
133 { FP_FNAME(
"conj") 1, FuncDefinition::ComplexOnly },
134 { FP_FNAME(
"cos") 1, FuncDefinition::AngleIn },
135 { FP_FNAME(
"cosh") 1, FuncDefinition::AngleIn },
136 { FP_FNAME(
"cot") 1, FuncDefinition::AngleIn },
137 { FP_FNAME(
"csc") 1, FuncDefinition::AngleIn },
138 { FP_FNAME(
"exp") 1, 0 },
139 { FP_FNAME(
"exp2") 1, 0 },
140 { FP_FNAME(
"floor") 1, 0 },
141 { FP_FNAME(
"hypot") 2, 0 },
142 { FP_FNAME(
"if") 0, FuncDefinition::OkForInt },
143 { FP_FNAME(
"imag") 1, FuncDefinition::ComplexOnly },
144 { FP_FNAME(
"int") 1, 0 },
145 { FP_FNAME(
"log") 1, 0 },
146 { FP_FNAME(
"log10") 1, 0 },
147 { FP_FNAME(
"log2") 1, 0 },
148 { FP_FNAME(
"max") 2, FuncDefinition::OkForInt },
149 { FP_FNAME(
"min") 2, FuncDefinition::OkForInt },
150 { FP_FNAME(
"polar") 2, FuncDefinition::ComplexOnly | FuncDefinition::AngleIn },
151 { FP_FNAME(
"pow") 2, 0 },
152 { FP_FNAME(
"real") 1, FuncDefinition::ComplexOnly },
153 { FP_FNAME(
"sec") 1, FuncDefinition::AngleIn },
154 { FP_FNAME(
"sin") 1, FuncDefinition::AngleIn },
155 { FP_FNAME(
"sinh") 1, FuncDefinition::AngleIn },
156 { FP_FNAME(
"sqrt") 1, 0 },
157 { FP_FNAME(
"tan") 1, FuncDefinition::AngleIn },
158 { FP_FNAME(
"tanh") 1, FuncDefinition::AngleIn },
159 { FP_FNAME(
"trunc") 1, 0 }
168 NamePtr(
const char* n,
unsigned l): name(n), nameLength(l) {}
170 inline bool operator==(
const NamePtr& rhs)
const 172 return nameLength == rhs.nameLength
173 && std::memcmp(name, rhs.name, nameLength) == 0;
175 inline bool operator<(
const NamePtr& rhs)
const 177 for(
unsigned i = 0; i < nameLength; ++i)
179 if(i == rhs.nameLength)
return false;
180 const char c1 = name[i], c2 = rhs.name[i];
181 if(c1 < c2)
return true;
182 if(c2 < c1)
return false;
184 return nameLength < rhs.nameLength;
188 template<
typename Value_t>
191 enum DataType { CONSTANT, UNIT, FUNC_PTR, PARSER_PTR, VARIABLE };
196 NameData(DataType t,
unsigned v) : type(t), index(v), value() { }
197 NameData(DataType t, Value_t v) : type(t), index(), value(v) { }
201 template<
typename Value_t>
202 class NamePtrsMap:
public 203 std::map<FUNCTIONPARSERTYPES::NamePtr,
204 FUNCTIONPARSERTYPES::NameData<Value_t> >
208 const unsigned FUNC_AMOUNT =
sizeof(Functions)/
sizeof(Functions[0]);
209 #endif // ONCE_FPARSER_H_ 212 #ifdef ONCE_FPARSER_H_ 215 template<
typename Value_t>
218 unsigned mReferenceCounter;
221 ParseErrorType mParseErrorType;
223 bool mUseDegreeConversion;
224 bool mHasByteCodeFlags;
225 const char* mErrorLocation;
227 unsigned mVariablesAmount;
228 std::string mVariablesString;
229 FUNCTIONPARSERTYPES::NamePtrsMap<Value_t> mNamePtrs;
231 struct InlineVariable
233 FUNCTIONPARSERTYPES::NamePtr mName;
234 unsigned mFetchIndex;
237 typedef std::vector<InlineVariable> InlineVarNamesContainer;
238 InlineVarNamesContainer mInlineVarNames;
240 struct FuncWrapperPtrData
246 FunctionPtr mRawFuncPtr;
247 FunctionWrapper* mFuncWrapperPtr;
250 FuncWrapperPtrData();
251 ~FuncWrapperPtrData();
252 FuncWrapperPtrData(
const FuncWrapperPtrData&);
253 FuncWrapperPtrData& operator=(
const FuncWrapperPtrData&);
256 struct FuncParserPtrData
262 std::vector<FuncWrapperPtrData> mFuncPtrs;
263 std::vector<FuncParserPtrData> mFuncParsers;
265 std::vector<unsigned> mByteCode;
266 std::vector<Value_t> mImmed;
268 #if !defined(FP_USE_THREAD_SAFE_EVAL) && \ 269 !defined(FP_USE_THREAD_SAFE_EVAL_WITH_ALLOCA) 270 std::vector<Value_t> mStack;
279 Data& operator=(
const Data&);
bool operator<(long lhs, const GmpInt &rhs)
bool operator==(T *p, const scoped_ptr< T > &b)