boxtype.cpp File Reference

A simple type system for block diagram expressions. The type of a block diagram is defined by a number of inputs and outputs. More...

#include <stdio.h>
#include <string.h>
#include "boxes.hh"
#include "ppbox.hh"
#include "prim2.hh"
#include "xtended.hh"
Include dependency graph for boxtype.cpp:

Go to the source code of this file.

Functions

static bool infereBoxType (Tree t, int *inum, int *onum)
 Infere the type (number of inputs and outputs) of a box.
bool getBoxType (Tree box, int *inum, int *onum)
 Return the type (number of inputs and outputs) of a box or false if undefined.

Variables

Tree BOXTYPEPROP = tree(symbol("boxTypeProp"))

Detailed Description

A simple type system for block diagram expressions. The type of a block diagram is defined by a number of inputs and outputs.

Author:
Yann Orlarey
Version:
1.0
Date:
2003

Definition in file boxtype.cpp.


Function Documentation

bool getBoxType ( Tree  box,
int *  inum,
int *  onum 
)

Return the type (number of inputs and outputs) of a box or false if undefined.

Parameters:
box the box we want to know the type
inum the place to return the number of inputs
onum the place to return the number of outputs
Returns:
true if type is defined, false if undefined

Definition at line 63 of file boxtype.cpp.

References cons(), Node::getInt(), getProperty(), hd(), infereBoxType(), isNil(), nil, CTree::node(), setProperty(), tl(), and tree().

Referenced by applyList(), boxlistOutputs(), eval2double(), eval2int(), generateDiagramSchema(), getBoxInputsAndOutputs(), infereBoxType(), isBoxNumeric(), main(), mapGetEqName(), propagate(), and replaceBoxNumeric().

00064 {
00065     Tree t;
00066     if (getProperty(box, BOXTYPEPROP, t)) {
00067         
00068         if (isNil(t)) {
00069             return false;
00070         } else {
00071             *inum = hd(t)->node().getInt();
00072             *onum = tl(t)->node().getInt();
00073             return true;
00074         }
00075         
00076     } else {
00077     
00078         if (infereBoxType(box, inum, onum)) {
00079             setProperty(box, BOXTYPEPROP, cons(tree(*inum), tree(*onum)));
00080             return true;
00081         } else {
00082             setProperty(box, BOXTYPEPROP, nil);
00083             return false;
00084         }
00085     }
00086 }

Here is the call graph for this function:

Here is the caller graph for this function:

static bool infereBoxType ( Tree  t,
int *  inum,
int *  onum 
) [static]

Infere the type (number of inputs and outputs) of a box.

Parameters:
box the box we want to know the type
inum the place to return the number of inputs
onum the place to return the number of outputs

Definition at line 97 of file boxtype.cpp.

References xtended::arity(), ffarity(), getBoxType(), getUserData(), isBoxButton(), isBoxCheckbox(), isBoxCut(), isBoxEnvironment(), isBoxFConst(), isBoxFFun(), isBoxFVar(), isBoxHBargraph(), isBoxHGroup(), isBoxHSlider(), isBoxInt(), isBoxMerge(), isBoxNumEntry(), isBoxPar(), isBoxPrim0(), isBoxPrim1(), isBoxPrim2(), isBoxPrim3(), isBoxPrim4(), isBoxPrim5(), isBoxReal(), isBoxRec(), isBoxSeq(), isBoxSlot(), isBoxSplit(), isBoxSymbolic(), isBoxTGroup(), isBoxVBargraph(), isBoxVGroup(), isBoxVSlider(), isBoxWire(), max(), and Automaton::s.

Referenced by getBoxType().

00098 {
00099     Tree a, b, ff, l, s;
00100     //Tree abstr, genv, vis, lenv;
00101     
00102     xtended* p = (xtended*) getUserData(t);
00103 
00104     if (p)                      { *inum = p->arity(); *onum = 1; }
00105     else if (isBoxInt(t))       { *inum = 0; *onum = 1; } 
00106     else if (isBoxReal(t))      { *inum = 0; *onum = 1; } 
00107     else if (isBoxWire(t))      { *inum = 1; *onum = 1; }
00108     else if (isBoxCut(t))       { *inum = 1; *onum = 0; } 
00109 
00110     else if (isBoxSlot(t))      { *inum = 0; *onum = 1; } 
00111     else if (isBoxSymbolic(t,s,b))  { if (!getBoxType(b, inum, onum)) return false; *inum += 1; } 
00112     
00113     else if (isBoxPrim0(t))     { *inum = 0; *onum = 1; } 
00114     else if (isBoxPrim1(t))     { *inum = 1; *onum = 1; } 
00115     else if (isBoxPrim2(t))     { *inum = 2; *onum = 1; } 
00116     else if (isBoxPrim3(t))     { *inum = 3; *onum = 1; } 
00117     else if (isBoxPrim4(t))     { *inum = 4; *onum = 1; } 
00118     else if (isBoxPrim5(t))     { *inum = 5; *onum = 1; } 
00119         
00120     else if (isBoxFFun(t,ff))   { *inum = ffarity(ff); *onum = 1; } 
00121     else if (isBoxFConst(t))    { *inum = 0; *onum = 1; } 
00122     else if (isBoxFVar(t))      { *inum = 0; *onum = 1; } 
00123     
00124     else if (isBoxButton(t))    { *inum = 0; *onum = 1; } 
00125     else if (isBoxCheckbox(t))  { *inum = 0; *onum = 1; } 
00126     else if (isBoxVSlider(t))   { *inum = 0; *onum = 1; } 
00127     else if (isBoxHSlider(t))   { *inum = 0; *onum = 1; } 
00128     else if (isBoxNumEntry(t))  { *inum = 0; *onum = 1; } 
00129     else if (isBoxVGroup(t,l,a)){ if (!getBoxType(a, inum, onum)) return false; } 
00130     else if (isBoxHGroup(t,l,a)){ if (!getBoxType(a, inum, onum)) return false; } 
00131     else if (isBoxTGroup(t,l,a)){ if (!getBoxType(a, inum, onum)) return false; } 
00132     
00133     else if (isBoxVBargraph(t))     { *inum = 1; *onum = 1; } 
00134     else if (isBoxHBargraph(t))     { *inum = 1; *onum = 1; } 
00135 
00136     else if (isBoxSeq(t, a, b)) {
00137         
00138         int u,v,x,y;
00139         if (!getBoxType(a, &u, &v)) return false;
00140         if (!getBoxType(b, &x, &y)) return false;
00141 
00142         if (v != x) {
00143             cerr    << "Error in sequential composition (A:B)" << endl
00144                     << "The number of outputs (" << v << ") of A = " << boxpp(a) << endl
00145                     << "must be equal to the number of inputs (" << x << ") of B : " << boxpp(b) << endl;
00146             exit(1);
00147         } else {
00148             *inum = u; *onum = y;
00149         }
00150 
00151     } else if (isBoxPar(t, a, b)) {
00152         
00153         int u,v,x,y;
00154         if (!getBoxType(a, &u, &v)) return false;
00155         if (!getBoxType(b, &x, &y)) return false;
00156 
00157         *inum = u+x; *onum = v+y;
00158 
00159     } else if (isBoxSplit(t, a, b)) {
00160         
00161         int u,v,x,y;
00162         if (!getBoxType(a, &u, &v)) return false;
00163         if (!getBoxType(b, &x, &y)) return false;
00164 
00165         if (v == 0) {
00166             cerr    << "Connection error in : " << boxpp(t) << endl
00167                     << "The first expression : " << boxpp(a) << " has no outputs" << endl;
00168             exit(1);
00169         }
00170         
00171         if (x == 0) {
00172             cerr    << "Connection error in : " << boxpp(t) << endl
00173                     << "The second expression : " << boxpp(b) << " has no inputs" << endl;
00174             exit(1);
00175         }
00176          
00177         if (x % v != 0) {
00178             cerr    << "Connection error in : " << boxpp(t) << endl
00179                     << "The number of outputs " << v
00180                     << " of the first expression should be a divisor of the number of inputs " << x
00181                     << " of the second expression" << endl;
00182             exit(1);
00183         }
00184         
00185         *inum = u; *onum = y;
00186 
00187     } else if (isBoxMerge(t, a, b)) {
00188         
00189         int u,v,x,y;
00190         if (!getBoxType(a, &u, &v)) return false;
00191         if (!getBoxType(b, &x, &y)) return false;
00192 
00193         if (v == 0) {
00194             cerr    << "Connection error in : " << boxpp(t) << endl
00195                     << "The first expression : " << boxpp(a) << " has no outputs" << endl;
00196             exit(1);
00197         }
00198         
00199         if (x == 0) {
00200             cerr    << "Connection error in : " << boxpp(t) << endl
00201                     << "The second expression : " << boxpp(b) << " has no inputs" << endl;
00202             exit(1);
00203         }
00204         
00205         if (v % x != 0) { 
00206             cerr    << "Connection error in : " << boxpp(t) << endl
00207                     << "The number of outputs " << v
00208                     << " of the first expression should be a multiple of the number of inputs " << x
00209                     << " of the second expression" << endl;
00210             exit(1);
00211         }
00212 
00213         *inum = u; *onum = y;
00214 
00215     } else if (isBoxRec(t, a, b)) {
00216         
00217         int u,v,x,y;
00218         if (!getBoxType(a, &u, &v)) return false;
00219         if (!getBoxType(b, &x, &y)) return false;
00220         if ( (x > v) | (y > u) ) { 
00221             cerr    << "Connection error in : " << boxpp(t) << endl;
00222             if (x > v) cerr << "The number of outputs " << v 
00223                             << " of the first expression should be greater or equal \n  to the number of inputs " << x 
00224                             << " of the second exepression" << endl;
00225             if (y > u) cerr << "The number of inputs " << u
00226                             << " of the first expression should be greater or equal \n  to the number of outputs " << y
00227                             << " of the second exepression" << endl;
00228             exit(1);
00229         }
00230         *inum = max(0,u-y); *onum = v;
00231         
00232     } else if (isBoxEnvironment(t)) {
00233         cerr << "An environment is not a block-diagram : " << boxpp(t) << endl;
00234         return false;
00235     } else {
00236       return false;
00237     }
00238     return true;
00239 }   

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Tree BOXTYPEPROP = tree(symbol("boxTypeProp"))

Definition at line 50 of file boxtype.cpp.

Generated on Thu Jul 15 15:46:56 2010 for FAUST compiler by  doxygen 1.6.3