FAUST compiler  0.9.9.6b8
Public Member Functions | List of all members
MinPrim Class Reference
Inheritance diagram for MinPrim:
Inheritance graph
[legend]
Collaboration diagram for MinPrim:
Collaboration graph
[legend]

Public Member Functions

 MinPrim ()
 
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)
 
- Public Member Functions inherited from xtended
 xtended (const char *name)
 
virtual ~xtended ()
 
Sym symbol ()
 
const char * name ()
 
Tree box ()
 
virtual bool isSpecialInfix ()
 generaly false, but true for binary op # such that #(x) == _::x More...
 

Detailed Description

Definition at line 8 of file minprim.cpp.

Constructor & Destructor Documentation

MinPrim::MinPrim ( )
inline

Definition at line 13 of file minprim.cpp.

13 : xtended("min") {}
xtended(const char *name)
Definition: xtended.hh:18

Member Function Documentation

virtual unsigned int MinPrim::arity ( )
inlinevirtual

Implements xtended.

Definition at line 15 of file minprim.cpp.

Referenced by computeSigOutput(), generateCode(), generateLateq(), infereSigOrder(), and infereSigType().

15 { return 2; }

Here is the caller graph for this function:

virtual Tree MinPrim::computeSigOutput ( const vector< Tree > &  args)
inlinevirtual

Implements xtended.

Definition at line 36 of file minprim.cpp.

References arity(), isDouble(), isInt(), min(), xtended::symbol(), and tree().

37  {
38  double f,g; int i,j;
39 
40  assert (args.size() == arity());
41 
42  if (isDouble(args[0]->node(),&f)) {
43 
44  if (isDouble(args[1]->node(), &g)) {
45  return tree(min(f, g));
46  } else if (isInt(args[1]->node(),&j)) {
47  return tree(min(f, double(j)));
48  } else {
49  return tree(symbol(), args[0], args[1]);
50  }
51 
52  } else if (isInt(args[0]->node(),&i)) {
53 
54  if (isDouble(args[1]->node(), &g)) {
55  return tree(min(double(i), g));
56  } else if (isInt(args[1]->node(),&j)) {
57  return tree(min(i, j));
58  } else {
59  return tree(symbol(), args[0], args[1]);
60  }
61 
62  } else {
63 
64  return tree(symbol(), args[0], args[1]);
65  }
66  }
bool isDouble(const Node &n)
Definition: node.hh:143
Sym symbol()
Definition: xtended.hh:24
virtual unsigned int arity()
Definition: minprim.cpp:15
Tree tree(const Node &n)
Definition: tree.hh:186
bool isInt(const Node &n)
Definition: node.hh:126
double min(double x, double y)
Definition: interval.hh:59

Here is the call graph for this function:

virtual string MinPrim::generateCode ( Klass klass,
const vector< string > &  args,
const vector< Type > &  types 
)
inlinevirtual

Implements xtended.

Definition at line 94 of file minprim.cpp.

References arity(), icast(), kBool, kInt, kNum, kReal, and subst().

95  {
96  assert (args.size() == arity());
97  assert (types.size() == arity());
98 
99  // generates code compatible with overloaded min
100  int n0 = types[0]->nature();
101  int n1 = types[1]->nature();
102  if (n0==kReal) {
103  if (n1==kReal) {
104  // both are floats, no need to cast
105  return subst("min($0, $1)", args[0], args[1]);
106  } else {
107  assert(n1==kInt); // second argument is not float, cast it to float
108  return subst("min($0, $2$1)", args[0], args[1], icast());
109  }
110  } else if (n1==kReal) {
111  assert(n0==kInt); // first not float but second is, cast first to float
112  return subst("min($2$0, $1)", args[0], args[1], icast());
113  } else {
114  assert(n0==kInt); assert(n1==kInt); // both are integers, check for booleans
115  int b0 = types[0]->boolean();
116  int b1 = types[1]->boolean();
117  if (b0==kNum) {
118  if (b1==kNum) {
119  // both are integers, no need to cast
120  return subst("min($0, $1)", args[0], args[1]);
121  } else {
122  assert(b1==kBool); // second is boolean, cast to int
123  return subst("min($0, (int)$1)", args[0], args[1]);
124  }
125  } else if (b1==kNum) {
126  assert(b0==kBool); // first is boolean, cast to int
127  return subst("min((int)$0, $1)", args[0], args[1], icast());
128  } else {
129  assert(b0==kBool); assert(b1==kBool); // both are booleans, no need to cast
130  return subst("min((int)$0, (int)$1)", args[0], args[1]);
131  }
132  }
133  }
Definition: sigtype.hh:54
const char * icast()
Definition: floats.cpp:47
Definition: sigtype.hh:55
string subst(const string &model, const vector< string > &args)
Text substitution.
Definition: Text.cpp:47
Definition: sigtype.hh:55
Definition: sigtype.hh:54
virtual unsigned int arity()
Definition: minprim.cpp:15

Here is the call graph for this function:

virtual string MinPrim::generateLateq ( Lateq lateq,
const vector< string > &  args,
const vector< Type > &  types 
)
inlinevirtual

Implements xtended.

Definition at line 135 of file minprim.cpp.

References arity(), infereSigType(), and subst().

136  {
137  assert (args.size() == arity());
138  assert (types.size() == arity());
139 
140  Type t = infereSigType(types);
141  return subst("\\min\\left( $0, $1 \\right)", args[0], args[1]);
142  }
string subst(const string &model, const vector< string > &args)
Text substitution.
Definition: Text.cpp:47
virtual unsigned int arity()
Definition: minprim.cpp:15
virtual Type infereSigType(const vector< Type > &types)
Definition: minprim.cpp:19

Here is the call graph for this function:

virtual int MinPrim::infereSigOrder ( const vector< int > &  args)
inlinevirtual

Implements xtended.

Definition at line 29 of file minprim.cpp.

References arity(), and max().

30  {
31  assert (args.size() == arity());
32  return max(args[0], args[1]);
33  }
double max(double x, double y)
Definition: interval.hh:60
virtual unsigned int arity()
Definition: minprim.cpp:15

Here is the call graph for this function:

virtual Type MinPrim::infereSigType ( const vector< Type > &  types)
inlinevirtual

Implements xtended.

Definition at line 19 of file minprim.cpp.

References arity(), castInterval(), and min().

Referenced by generateLateq().

20  {
21  assert (types.size() == arity());
22  interval i = types[0]->getInterval();
23  interval j = types[1]->getInterval();
24  return castInterval(types[0]|types[1], min(i,j));
25  }
virtual unsigned int arity()
Definition: minprim.cpp:15
Type castInterval(Type t, const interval &i)
Definition: sigtype.hh:278
double min(double x, double y)
Definition: interval.hh:59

Here is the call graph for this function:

Here is the caller graph for this function:

virtual bool MinPrim::needCache ( )
inlinevirtual

Implements xtended.

Definition at line 17 of file minprim.cpp.

17 { return true; }
virtual void MinPrim::sigVisit ( Tree  sig,
sigvisitor visitor 
)
inlinevirtual

Definition at line 27 of file minprim.cpp.

27 {}

The documentation for this class was generated from the following file: