Inherits xtended.
Public Member Functions | |
MaxPrim () | |
virtual unsigned int | arity () |
virtual bool | needCache () |
virtual Type | infereSigType (const vector< Type > &types) |
virtual void | sigVisit (Tree sig, sigvisitor *visitor) |
virtual int | infereSigOrder (const vector< int > &args) |
virtual Tree | computeSigOutput (const vector< Tree > &args) |
virtual string | generateCode (Klass *klass, const vector< string > &args, const vector< Type > &types) |
virtual string | generateLateq (Lateq *lateq, const vector< string > &args, const vector< Type > &types) |
Definition at line 8 of file maxprim.cpp.
MaxPrim::MaxPrim | ( | ) | [inline] |
Definition at line 13 of file maxprim.cpp.
00013 : xtended("max") {}
virtual unsigned int MaxPrim::arity | ( | ) | [inline, virtual] |
Implements xtended.
Definition at line 15 of file maxprim.cpp.
Referenced by computeSigOutput(), generateCode(), generateLateq(), infereSigOrder(), and infereSigType().
Implements xtended.
Definition at line 36 of file maxprim.cpp.
References arity(), isDouble(), isInt(), max(), xtended::symbol(), and tree().
00037 { 00038 double f,g; int i,j; 00039 00040 assert (args.size() == arity()); 00041 00042 if (isDouble(args[0]->node(),&f)) { 00043 00044 if (isDouble(args[1]->node(), &g)) { 00045 return tree(max(f, g)); 00046 } else if (isInt(args[1]->node(),&j)) { 00047 return tree(max(f, double(j))); 00048 } else { 00049 return tree(symbol(), args[0], args[1]); 00050 } 00051 00052 } else if (isInt(args[0]->node(),&i)) { 00053 00054 if (isDouble(args[1]->node(), &g)) { 00055 return tree(max(double(i), g)); 00056 } else if (isInt(args[1]->node(),&j)) { 00057 return tree(max(i, j)); 00058 } else { 00059 return tree(symbol(), args[0], args[1]); 00060 } 00061 00062 } else { 00063 00064 return tree(symbol(), args[0], args[1]); 00065 } 00066 }
virtual string MaxPrim::generateCode | ( | Klass * | klass, | |
const vector< string > & | args, | |||
const vector< Type > & | types | |||
) | [inline, virtual] |
Implements xtended.
Definition at line 68 of file maxprim.cpp.
References arity(), infereSigType(), kReal, and subst().
00069 { 00070 assert (args.size() == arity()); 00071 assert (types.size() == arity()); 00072 00073 Type t = infereSigType(types); 00074 if (t->nature() == kReal) { 00075 return subst("max($0, $1)", args[0], args[1]); 00076 } else { 00077 return subst("max($0, $1)", args[0], args[1]); 00078 } 00079 }
virtual string MaxPrim::generateLateq | ( | Lateq * | lateq, | |
const vector< string > & | args, | |||
const vector< Type > & | types | |||
) | [inline, virtual] |
Implements xtended.
Definition at line 81 of file maxprim.cpp.
References arity(), infereSigType(), and subst().
00082 { 00083 assert (args.size() == arity()); 00084 assert (types.size() == arity()); 00085 00086 Type t = infereSigType(types); 00087 return subst("\\max\\left( $0, $1 \\right)", args[0], args[1]); 00088 }
virtual int MaxPrim::infereSigOrder | ( | const vector< int > & | args | ) | [inline, virtual] |
Implements xtended.
Definition at line 19 of file maxprim.cpp.
References arity(), castInterval(), and max().
Referenced by generateCode(), and generateLateq().
00020 { 00021 assert (types.size() == arity()); 00022 interval i = types[0]->getInterval(); 00023 interval j = types[1]->getInterval(); 00024 return castInterval(types[0]|types[1], max(i,j)); 00025 }
virtual bool MaxPrim::needCache | ( | ) | [inline, virtual] |
virtual void MaxPrim::sigVisit | ( | Tree | sig, | |
sigvisitor * | visitor | |||
) | [inline, virtual] |
Definition at line 27 of file maxprim.cpp.