sigtyperules.cpp File Reference

#include <stdio.h>
#include <assert.h>
#include "sigtype.hh"
#include "sigprint.hh"
#include "ppsig.hh"
#include "prim2.hh"
#include "tlib.hh"
#include "sigtyperules.hh"
#include "xtended.hh"
#include "recursivness.hh"
Include dependency graph for sigtyperules.cpp:

Go to the source code of this file.

Functions

static Type getInferredType (Tree term, Tree env)
 Retrieve or infere the type of a term according to its surrounding type environment.
static Type infereSigType (Tree sig, Tree env)
 Infere the type of a term according to its surrounding type environment.
static Type infereFFType (Tree ff, Tree ls, Tree env)
 Infere the type of a foreign function call.
static Type infereFConstType (Tree type)
 Infere the type of a foreign constant.
static Type infereFVarType (Tree type)
 Infere the type of a foreign variable.
static Type infereRecType (Tree var, Tree body, Tree env)
 Infere the type of e recursive block by trying solutions of increasing generality.
static Type infereReadTableType (Type tbl, Type ri)
 Infere the type of the result of reading a table.
static Type infereWriteTableType (Type tbl, Type wi, Type wd)
 Infere the type of the result of writing into a table.
static Type infereProjType (Type t, int i, int vec)
 Infere the type of a projection (selection) of a tuplet element.
static Type infereXType (Tree sig, Tree env)
 Infere the type of an extended (primitive) block.
static Type infereDocConstantTblType (Type size, Type init)
static Type infereDocWriteTblType (Type size, Type init, Type widx, Type wsig)
static Type infereDocAccessTblType (Type tbl, Type ridx)
void setSigType (Tree sig, Type t)
 set the type annotation of sig
Type getSigType (Tree sig)
 retrieve the type annotation of sig
Tree addEnv (Tree var, Type tp, Tree env)
 add a new binding to a type environment
Type searchEnv (Tree env, Tree var)
 search for the type associated to a variable
static bool isInEnv (Tree env, Tree var, Type &val)
 search for the type associated to a variable
void typeAnnotation (Tree sig)
 fully annotate every subtree of term with type information
Type T (Tree term, Tree env)
 Shortcut to getSigType, retrieve or infere the type of a term according to its surrounding type environment.
static interval __arithmetic (int opcode, const interval &x, const interval &y)
 Compute the resulting interval of an arithmetic operation.
static interval arithmetic (int opcode, const interval &x, const interval &y)
static Type initialRecType (Tree t)
 Compute an initial type solution for a recursive block.

Variables

Tree TYPEPROPERTY = tree(symbol("TypeProperty"))
Tree NULLENV = tree(symbol("NullEnv"))
 The empty type environment (also property key for closed term type).

Function Documentation

static interval __arithmetic ( int  opcode,
const interval x,
const interval y 
) [static]

Compute the resulting interval of an arithmetic operation.

Parameters:
op code of the operation
s1 interval of the left operand
s2 interval of the right operand
Returns:
the resulting interval

Definition at line 234 of file sigtyperules.cpp.

References kAdd, kAND, kDiv, kEQ, kGE, kGT, kLE, kLsh, kLT, kMul, kNE, kOR, kRem, kRsh, kSub, and kXOR.

Referenced by arithmetic().

00235 {
00236     switch (opcode) {
00237         case kAdd: return x+y;
00238         case kSub: return x-y;
00239         case kMul:  return x*y;
00240         case kDiv: return x/y;
00241         case kRem: return x%y;
00242         case kLsh: return x<<y;
00243         case kRsh: return x>>y;
00244         case kGT:  return x>y;
00245         case kLT:  return x<y;
00246         case kGE:  return x>=y;
00247         case kLE:  return x<=y;
00248         case kEQ:  return x==y;
00249         case kNE:   return x!=y;
00250         case kAND:  return x&y;
00251         case kOR:  return x|y;
00252         case kXOR: return x^y;
00253         default:
00254             cerr << "Unrecognized opcode : " << opcode << endl;
00255             exit(1);
00256     }
00257         
00258     return interval();
00259 }

Here is the caller graph for this function:

Tree addEnv ( Tree  var,
Type  tp,
Tree  env 
)

add a new binding to a type environment

Parameters:
var the variable
type the type of the variable
env the type environment
Returns:
a new environment : [(var,type):env]

Definition at line 117 of file sigtyperules.cpp.

References cons(), and tree().

Referenced by infereRecType().

00118 {
00119     Tree r = cons(cons(var,tree((AudioType*)tp)),env);
00120     return r;
00121 }

Here is the call graph for this function:

Here is the caller graph for this function:

static interval arithmetic ( int  opcode,
const interval x,
const interval y 
) [static]

Definition at line 261 of file sigtyperules.cpp.

References __arithmetic().

Referenced by infereSigType().

00262 {
00263     interval r = __arithmetic(opcode,x,y);
00264     return r;
00265 }

Here is the call graph for this function:

Here is the caller graph for this function:

Type getInferredType ( Tree  term,
Tree  env 
) [static]

Retrieve or infere the type of a term according to its surrounding type environment.

Parameters:
sig the signal to analyze
env the type environment
Returns:
the type of sig according to environment env

Definition at line 184 of file sigtyperules.cpp.

References getProperty(), CTree::getType(), infereSigType(), isInEnv(), setProperty(), setSigType(), tree(), and tree2ptr().

Referenced by T(), and typeAnnotation().

00185 {
00186     AudioType* at = (AudioType*) term->getType();
00187     if (at) { 
00188         return at; 
00189     } else {
00190         Tree    tt;
00191         if (!getProperty(term, env, tt)) {
00192             Type tp;
00193             if (!isInEnv(env, term, tp)) {
00194                 Type t = infereSigType(term, env);
00195                 if (env == NULLENV) {
00196                     setSigType(term, t);                    // the result is sure
00197                 } else {
00198                     setProperty(term, env, tree((void*)t)); // the result depends of hypothesis
00199                 }
00200                 return t;
00201             } else {
00202                 return tp;
00203             }
00204         }
00205         Type rt((AudioType*)tree2ptr(tt));
00206         return rt;
00207     }
00208 }

Here is the call graph for this function:

Here is the caller graph for this function:

Type getSigType ( Tree  sig  ) 

retrieve the type annotation of sig

Parameters:
sig the signal we want to know the type

Definition at line 82 of file sigtyperules.cpp.

References CTree::getType().

Referenced by DocCompiler::generateBinOp(), DocCompiler::generateCacheCode(), VectorCompiler::generateCacheCode(), ScalarCompiler::generateCacheCode(), DocCompiler::generateDelayVec(), ScalarCompiler::generateDelayVec(), DocCompiler::generateDocConstantTbl(), DocCompiler::generateDocWriteTbl(), DocCompiler::generateFConst(), ScalarCompiler::generateFConst(), DocCompiler::generateFVar(), DocCompiler::generateHBargraph(), ScalarCompiler::generateHBargraph(), DocCompiler::generateNumber(), ScalarCompiler::generateNumber(), ScalarCompiler::generatePrefix(), DocCompiler::generateRec(), ScalarCompiler::generateRec(), ScalarCompiler::generateStaticTable(), ScalarCompiler::generateTable(), DocCompiler::generateVariableStore(), VectorCompiler::generateVariableStore(), ScalarCompiler::generateVariableStore(), DocCompiler::generateVBargraph(), ScalarCompiler::generateVBargraph(), DocCompiler::generateXtended(), ScalarCompiler::generateXtended(), OccMarkup::incOcc(), VectorCompiler::needSeparateLoop(), ScalarCompiler::sharingAnnotation(), DocCompiler::sharingAnnotation(), and signal2klass().

00083 {
00084     AudioType* t = (AudioType*) sig->getType();
00085     if (t==0) {
00086         cerr << "ERROR in getSigType : no type information available for signal :" << *sig << endl;
00087         exit(1);
00088     }
00089     return t;   
00090 }

Here is the call graph for this function:

Here is the caller graph for this function:

static Type infereDocAccessTblType ( Type  tbl,
Type  ridx 
) [static]

Definition at line 547 of file sigtyperules.cpp.

Referenced by infereSigType().

00548 {
00549     Type temp =  tbl
00550       ->promoteVariability(ridx->variability())
00551       ->promoteComputability(ridx->computability())
00552       ->promoteVectorability(ridx->vectorability())
00553       ;
00554     return temp;
00555 }

Here is the caller graph for this function:

static Type infereDocConstantTblType ( Type  size,
Type  init 
) [static]

Definition at line 526 of file sigtyperules.cpp.

References checkInit(), checkInt(), and checkKonst().

Referenced by infereSigType().

00527 {
00528     checkKonst(checkInt(checkInit(size)));
00529 
00530     return init;
00531 }

Here is the call graph for this function:

Here is the caller graph for this function:

static Type infereDocWriteTblType ( Type  size,
Type  init,
Type  widx,
Type  wsig 
) [static]

Definition at line 533 of file sigtyperules.cpp.

References checkInit(), checkInt(), checkKonst(), kSamp, and kScal.

Referenced by infereSigType().

00534 {
00535     checkKonst(checkInt(checkInit(size)));
00536 
00537     Type temp =  init
00538       ->promoteVariability(kSamp)       // difficult to tell, therefore kSamp to be safe
00539       ->promoteComputability(widx->computability()|wsig->computability())
00540       ->promoteVectorability(kScal)     // difficult to tell, therefore kScal to be safe
00541       ->promoteNature(wsig->nature())   // nature of the initial and written signal
00542       ->promoteBoolean(wsig->boolean()) // booleanity of the initial and written signal
00543       ;
00544     return temp;
00545 }

Here is the call graph for this function:

Here is the caller graph for this function:

static Type infereFConstType ( Tree  type  )  [static]

Infere the type of a foreign constant.

Definition at line 630 of file sigtyperules.cpp.

References kInit, kKonst, kNum, kVect, and tree2int().

Referenced by infereSigType().

00631 {
00632     // une constante externe ne peut pas se calculer au plus tot qu'a
00633     // l'initialisation. Elle est constante, auquel cas on considere que c'est comme
00634     // rand() c'est a dire que le resultat varie a chaque appel.
00635     return new SimpleType(tree2int(type),kKonst,kInit,kVect,kNum, interval());
00636 }

Here is the call graph for this function:

Here is the caller graph for this function:

static Type infereFFType ( Tree  ff,
Tree  ls,
Tree  env 
) [static]

Infere the type of a foreign function call.

Definition at line 601 of file sigtyperules.cpp.

References ffarity(), ffrestype(), hd(), isList(), kInit, kInt, kKonst, kNum, kSamp, kVect, T(), and tl().

Referenced by infereSigType().

00602 {
00603     // une primitive externe ne peut pas se calculer au plus tot qu'a
00604     // l'initialisation. Sa variabilite depend de celle de ses arguments
00605     // sauf si elle n'en pas, auquel cas on considere que c'est comme
00606     // rand() c'est a dire que le resultat varie a chaque appel.
00607     if (ffarity(ff)==0) {
00608         // case of functions like rand()
00609         return new SimpleType(ffrestype(ff),kSamp,kInit,kVect,kNum, interval());
00610     } else {
00611         // otherwise variability and computability depends
00612         // arguments (OR of all arg types)
00613         Type t = new SimpleType(kInt,kKonst,kInit,kVect,kNum, interval());
00614         while (isList(ls)) { t = t|T(hd(ls),env); ls=tl(ls); }
00615         // but the result type is defined by the function
00616 
00617         //return t;
00618         return new SimpleType(  ffrestype(ff),
00619                                 t->variability(),
00620                                 t->computability(),
00621                                 t->vectorability(),
00622                                 t->boolean(),
00623                                 interval() );
00624     }
00625 }

Here is the call graph for this function:

Here is the caller graph for this function:

static Type infereFVarType ( Tree  type  )  [static]

Infere the type of a foreign variable.

Definition at line 641 of file sigtyperules.cpp.

References kBlock, kExec, kNum, kVect, and tree2int().

Referenced by infereSigType().

00642 {
00643     // une variable externe ne peut pas se calculer au plus tot qu'a
00644     // l'execution. Elle est varie par blocs comme les éléments d'interface utilisateur.
00645     return new SimpleType(tree2int(type),kBlock,kExec,kVect,kNum, interval());
00646 }

Here is the call graph for this function:

Here is the caller graph for this function:

static Type infereProjType ( Type  t,
int  i,
int  vec 
) [static]

Infere the type of a projection (selection) of a tuplet element.

Definition at line 423 of file sigtyperules.cpp.

References isTupletType(), kVect, and vecCast().

Referenced by infereSigType().

00424 {
00425     TupletType* tt = isTupletType(t);
00426     if (tt == 0) {
00427         cerr << "ERROR infering projection type, not a tuplet type : " << t << endl;
00428         exit(1);
00429     }
00430     //return (*tt)[i]   ->promoteVariability(t->variability())
00431     //      ->promoteComputability(t->computability());
00432     Type temp = (*tt)[i]    ->promoteVariability(t->variability())
00433       ->promoteComputability(t->computability())
00434       ->promoteVectorability(vec/*t->vectorability()*/);
00435     //->promoteBooleanity(t->boolean());
00436 
00437     if(vec==kVect) return vecCast(temp);
00438     else return temp;
00439 }

Here is the call graph for this function:

Here is the caller graph for this function:

static Type infereReadTableType ( Type  tbl,
Type  ri 
) [static]

Infere the type of the result of reading a table.

Definition at line 483 of file sigtyperules.cpp.

References AudioType::boolean(), AudioType::computability(), TableType::content(), isSimpleType(), isTableType(), kInt, AudioType::nature(), AudioType::variability(), and AudioType::vectorability().

Referenced by infereSigType().

00484 {
00485     TableType*  tt = isTableType(tbl);
00486     if (tt == 0) {
00487         cerr << "ERROR infering read table type, wrong table type : " << tbl << endl;
00488         exit(1);
00489     }
00490     SimpleType* st = isSimpleType(ri);
00491     if (st == 0 || st->nature() > kInt) {
00492         cerr << "ERROR infering read table type, wrong write index type : " << ri << endl;
00493         exit(1);
00494     }
00495 
00496     //cerr<<"Read Table type avant promote: "<<*tt<<endl;
00497     //cerr<<"Indice avant promote: "<<ri<<endl;
00498 
00499     //Type temp =  tt->content()->promoteVariability(ri->variability()|tt->variability())
00500     //  ->promoteComputability(ri->computability()|tt->computability());
00501 
00502     //cerr<<"Read Table type: "<<temp<<endl;
00503 
00504     //return temp;
00505 
00506     Type temp =  tt->content()->promoteVariability(ri->variability()|tt->variability())
00507       ->promoteComputability(ri->computability()|tt->computability())
00508       ->promoteVectorability(ri->vectorability()|tt->vectorability())
00509       ->promoteBoolean(ri->boolean()|tt->boolean())
00510       ;
00511 
00512     //cerr<<"Read Table type: "<<temp<<endl;
00513 
00514 
00515     return temp;
00516 
00517     //return tt->content(); // pas completement correct !!!
00518     //return tt->content()->promoteVariability(ri->variability())
00519     //          ->promoteComputability(ri->computability())
00520       //->promoteVectorability(ri->vectorability())
00521       //           ->promoteBoolean(ri->boolean())
00522       //             ;
00523 }

Here is the call graph for this function:

Here is the caller graph for this function:

static Type infereRecType ( Tree  var,
Tree  body,
Tree  env 
) [static]

Infere the type of e recursive block by trying solutions of increasing generality.

Definition at line 577 of file sigtyperules.cpp.

References addEnv(), getRecursivness(), initialRecType(), setProperty(), setSigType(), T(), and tree().

Referenced by infereSigType().

00578 {
00579     Type t0, t1;
00580 
00581     t1 = initialRecType(body);
00582     do {
00583         t0 = t1;
00584         setProperty(var, env, tree((void*)t0));
00585         t1 = T(body, addEnv(var, t0, env));
00586     } while (t1 > t0);
00587 
00588     assert (t1 == t0);
00589 
00590     if (getRecursivness(body) == 1 || env == NULLENV) {
00591         setSigType(var, t1);
00592         T(body, NULLENV);
00593     } 
00594     return t1;
00595 }

Here is the call graph for this function:

Here is the caller graph for this function:

static Type infereSigType ( Tree  sig,
Tree  env 
) [static]

Infere the type of a term according to its surrounding type environment.

Parameters:
sig the signal to aanlyze
env the type environment
Returns:
the type of sig according to environment env

Definition at line 275 of file sigtyperules.cpp.

References arithmetic(), AudioType::boolean(), castInterval(), checkInit(), checkInt(), AudioType::computability(), floatCast(), AudioType::getInterval(), getUserData(), hd(), infereDocAccessTblType(), infereDocConstantTblType(), infereDocWriteTblType(), infereFConstType(), infereFFType(), infereFVarType(), infereProjType(), infereReadTableType(), infereRecType(), infereWriteTableType(), infereXType(), intCast(), isList(), isProj(), isRec(), isSigAttach(), isSigBinOp(), isSigButton(), isSigCheckbox(), isSigDelay1(), isSigDocAccessTbl(), isSigDocConstantTbl(), isSigDocWriteTbl(), isSigFConst(), isSigFFun(), isSigFixDelay(), isSigFloatCast(), isSigFVar(), isSigGen(), isSigHBargraph(), isSigHSlider(), isSigInput(), isSigInt(), isSigIntCast(), isSigNumEntry(), isSigOutput(), isSigPrefix(), isSigRDTbl(), isSigReal(), isSigSelect2(), isSigSelect3(), isSigTable(), isSigVBargraph(), isSigVSlider(), isSigWRTbl(), isSimpleType(), kComp, kExec, kGT, kInt, kKonst, kNE, kNum, kReal, kSamp, kScal, kVect, interval::lo, max(), min(), name(), AudioType::nature(), print(), reunion(), sampCast(), T(), TGUI, tl(), tree2float(), interval::valid, AudioType::variability(), and AudioType::vectorability().

Referenced by getInferredType().

00276 {
00277     int         i;
00278     double      r;
00279     Tree        sel, s1, s2, s3, ff, id, ls, l, x, y, z, u, var, body, type, name, file;
00280     Tree        label, cur, min, max, step;
00281 
00282 
00283          if ( getUserData(sig) )            return infereXType(sig, env);
00284 
00285     else if (isSigInt(sig, &i))         return new SimpleType(kInt, kKonst, kComp, kVect, kNum, interval(i));
00286 
00287     else if (isSigReal(sig, &r))            return new SimpleType(kReal, kKonst, kComp, kVect, kNum, interval(r));
00288 
00289     else if (isSigInput(sig, &i))           return new SimpleType(kReal, kSamp, kExec, kVect, kNum, interval(-1,1));
00290 
00291     else if (isSigOutput(sig, &i, s1))  return sampCast(T(s1,env));
00292 
00293     else if (isSigDelay1(sig, s1))          { 
00294         Type t = T(s1,env); 
00295         return castInterval(sampCast(t), reunion(t->getInterval(), interval(0,0))); 
00296     }
00297 
00298     else if (isSigPrefix(sig, s1, s2))      { 
00299         Type t1 = T(s1,env); 
00300         Type t2 = T(s2,env); 
00301         checkInit(t1); 
00302         return castInterval(sampCast(t1|t2), reunion(t1->getInterval(), t2->getInterval())); 
00303     }
00304 
00305     else if (isSigFixDelay(sig, s1, s2))        { 
00306         Type t1 = T(s1,env); 
00307         Type t2 = T(s2,env);
00308         interval i = t2->getInterval();
00309  
00310 /*      cerr << "for sig fix delay : s1 = " 
00311                 << t1 << ':' << ppsig(s1) << ", s2 = " 
00312                 << t2 << ':' << ppsig(s2) << endl; */
00313         if (!i.valid) {
00314             cerr << "ERROR : can't compute the min and max values of : " << ppsig(s2) << endl;
00315             cerr << "        used in delay expression : " << ppsig(sig) << endl;
00316             cerr << "        (probably a recursive signal)" << endl;
00317             exit(1);
00318         } else if (i.lo < 0) {
00319             cerr << "ERROR : possible negative values of : " << ppsig(s2) << endl;
00320             cerr << "        used in delay expression : " << ppsig(sig) << endl;
00321             cerr << "        " << i << endl;
00322             exit(1);
00323         }
00324             
00325         return castInterval(sampCast(t1), reunion(t1->getInterval(), interval(0,0))); 
00326     }
00327 
00328     else if (isSigBinOp(sig, &i, s1, s2)) {
00329         //Type t = T(s1,env)|T(s2,env);
00330         Type t1 = T(s1,env);
00331         Type t2 = T(s2,env);
00332         Type t3 = castInterval(t1 | t2, arithmetic(i, t1->getInterval(), t2->getInterval()));
00333         //cerr <<"type rule for : " << ppsig(sig) << " -> " << *t3 << endl;
00334         //return (!gVectorSwitch && (i>=kGT) && (i<=kNE)) ?  intCast(t3) : t3; // for comparaison operation the result is int
00335         return ((i>=kGT) && (i<=kNE)) ?  intCast(t3) : t3; // for comparaison operation the result is int
00336     }
00337 
00338     else if (isSigIntCast(sig, s1))         return intCast(T(s1,env));
00339 
00340     else if (isSigFloatCast(sig, s1))           return floatCast(T(s1,env));
00341 
00342     else if (isSigFFun(sig, ff, ls))            return infereFFType(ff,ls,env);
00343 
00344     else if (isSigFConst(sig,type,name,file))   return infereFConstType(type);
00345 
00346     else if (isSigFVar(sig,type,name,file))   return infereFVarType(type);
00347 
00348     else if (isSigButton(sig))              return castInterval(TGUI,interval(0,1)); 
00349 
00350     else if (isSigCheckbox(sig))                return castInterval(TGUI,interval(0,1));
00351 
00352     else if (isSigVSlider(sig,label,cur,min,max,step))      
00353                                                 return castInterval(TGUI,interval(tree2float(min),tree2float(max)));
00354 
00355     else if (isSigHSlider(sig,label,cur,min,max,step))              
00356                                                 return castInterval(TGUI,interval(tree2float(min),tree2float(max)));
00357 
00358     else if (isSigNumEntry(sig,label,cur,min,max,step))             
00359                                                 return castInterval(TGUI,interval(tree2float(min),tree2float(max)));
00360 
00361     else if (isSigHBargraph(sig, l, x, y, s1)) return T(s1,env);
00362 
00363     else if (isSigVBargraph(sig, l, x, y, s1)) return T(s1,env);
00364 
00365     else if (isSigAttach(sig, s1, s2))      { T(s2,env); return T(s1,env); }
00366 
00367     else if (isRec(sig, var, body))         return infereRecType(sig, body, env);
00368 
00369     else if (isProj(sig, &i, s1))               return infereProjType(T(s1,env),i,kScal);
00370 
00371     else if (isSigTable(sig, id, s1, s2))       { checkInt(checkInit(T(s1,env))); return new TableType(checkInit(T(s2,env))); }
00372 
00373     else if (isSigWRTbl(sig, id, s1, s2, s3))   return infereWriteTableType(T(s1,env), T(s2,env), T(s3,env));
00374 
00375     else if (isSigRDTbl(sig, s1, s2))           return infereReadTableType(T(s1,env), T(s2,env));
00376 
00377     else if (isSigGen(sig, s1))                 return T(s1,NULLENV);
00378 
00379     else if ( isSigDocConstantTbl(sig, x, y) )  return infereDocConstantTblType(T(x,env), T(y,env));
00380     else if ( isSigDocWriteTbl(sig,x,y,z,u) )   return infereDocWriteTblType(T(x,env), T(y,env), T(z,env), T(u,env));
00381     else if ( isSigDocAccessTbl(sig, x, y) )    return infereDocAccessTblType(T(x,env), T(y,env));
00382 
00383     else if (isSigSelect2(sig,sel,s1,s2))       {
00384 
00385       SimpleType *st1, *st2, *stsel;
00386 
00387       st1 = isSimpleType(T(s1,env));
00388       st2 = isSimpleType(T(s2,env));
00389       stsel = isSimpleType(T(sel,env));
00390 
00391       return new SimpleType( st1->nature()|st2->nature(),
00392                  st1->variability()|st2->variability()|stsel->variability(),
00393                  st1->computability()|st2->computability()|stsel->computability(),
00394                  st1->vectorability()|st2->vectorability()|stsel->vectorability(),
00395                  st1->boolean()|st2->boolean(),
00396                  reunion(st1->getInterval(), st2->getInterval())
00397                  );
00398 
00399       //return T(sel,env)|T(s1,env)|T(s2,env);
00400 
00401     }
00402 
00403     else if (isSigSelect3(sig,sel,s1,s2,s3))    { return T(sel,env)|T(s1,env)|T(s2,env)|T(s3,env); }
00404 
00405     else if (isList(sig))
00406     {
00407         vector<Type> v;
00408         while (isList(sig)) { v.push_back(T(hd(sig),env)); sig = tl(sig); }
00409         return new TupletType(v);
00410     }
00411 
00412     // unrecognized signal here
00413     fprintf(stderr, "ERROR infering signal type : unrecognized signal  : "); print(sig, stderr); fprintf(stderr, "\n");
00414     exit(1);
00415     return 0;
00416 }

Here is the caller graph for this function:

static Type infereWriteTableType ( Type  tbl,
Type  wi,
Type  wd 
) [static]

Infere the type of the result of writing into a table.

Definition at line 446 of file sigtyperules.cpp.

References TableType::content(), isSimpleType(), isTableType(), kInt, and AudioType::nature().

Referenced by infereSigType().

00447 {
00448     TableType* tt = isTableType(tbl);
00449     if (tt == 0) {
00450         cerr << "ERROR infering write table type, wrong table type : " << tbl << endl;
00451         exit(1);
00452     }
00453     SimpleType* st = isSimpleType(wi);
00454     if (st == 0 || st->nature() > kInt) {
00455         cerr << "ERROR infering write table type, wrong write index type : " << wi << endl;
00456         exit(1);
00457     }
00458 
00459     int n = tt->nature();
00460     int v = wi->variability() | wd->variability();
00461     int c = wi->computability() | wd->computability();
00462     int vec = wi->vectorability() | wd->vectorability();
00463 
00464     //Type temp = tt->content();
00465     //cerr<<"Write table content: "<<temp<<endl;
00466 
00467     //Type tempbis = new TableType(/*tt->content()*/temp, v, c);
00468     //cerr<<"Write table ap� promotion: "<<tempbis<<endl;
00469 
00470     //return tempbis;
00471 
00472     //return new TableType(/*tt->content()*/temp, v, c);
00473 
00474     return new TableType(tt->content(), n, v, c, vec);
00475 
00476 }

Here is the call graph for this function:

Here is the caller graph for this function:

static Type infereXType ( Tree  sig,
Tree  env 
) [static]

Infere the type of an extended (primitive) block.

Definition at line 654 of file sigtyperules.cpp.

References CTree::arity(), CTree::branch(), getUserData(), xtended::infereSigType(), and T().

Referenced by infereSigType().

00655 {
00656     //cerr << "infereXType :" << endl;
00657     //cerr << "infereXType of " << *sig << endl;
00658     xtended* p = (xtended*) getUserData(sig);
00659     vector<Type> vt;
00660 
00661     for (int i = 0; i < sig->arity(); i++) vt.push_back(T(sig->branch(i), env));
00662     return p->infereSigType(vt);
00663 }

Here is the call graph for this function:

Here is the caller graph for this function:

static Type initialRecType ( Tree  t  )  [static]

Compute an initial type solution for a recursive block.

Definition at line 560 of file sigtyperules.cpp.

References hd(), isList(), tl(), and TREC.

Referenced by infereRecType().

00561 {
00562     if (isList(t)) {
00563         vector<Type> v;
00564         do { v.push_back(initialRecType(hd(t))); t = tl(t); }  while (isList(t));
00565         return new TupletType(v);
00566     } else {
00567         return TREC;
00568     }
00569 }

Here is the call graph for this function:

Here is the caller graph for this function:

static bool isInEnv ( Tree  env,
Tree  var,
Type val 
) [static]

search for the type associated to a variable

Parameters:
env the type environment (a list of pair(var,type))
var the variable to search
val where to put his type
Returns:
true when var has an associated type in env

Definition at line 151 of file sigtyperules.cpp.

References hd(), tl(), and tree2ptr().

Referenced by getInferredType().

00152 {
00153     while ( (env != NULLENV) && (hd(hd(env)) != var) ) { env = tl(env); }
00154     if (env == NULLENV) return false;
00155     val = Type((AudioType*)tree2ptr(tl(hd(env))));
00156     return true;
00157 }

Here is the call graph for this function:

Here is the caller graph for this function:

Type searchEnv ( Tree  env,
Tree  var 
)

search for the type associated to a variable

Parameters:
env the type environment
var the variable to search
Returns:
the type associated to var in env

Definition at line 130 of file sigtyperules.cpp.

References hd(), print(), tl(), and tree2ptr().

Referenced by propagate(), and sigMapRename().

00131 {
00132     while ( (env != NULLENV) && (hd(hd(env)) != var) ) { env = tl(env); }
00133     if (env == NULLENV) {
00134         cerr << "Problem in searchEnv "; print(var, stderr);
00135         cerr << " was not found" << endl;
00136         assert(env != NULLENV); // we should have found the data
00137     }
00138 
00139     return Type((AudioType*)tree2ptr(tl(hd(env))));
00140 }

Here is the call graph for this function:

Here is the caller graph for this function:

void setSigType ( Tree  sig,
Type  t 
)

set the type annotation of sig

Parameters:
sig the signal we want to type
t the type of the signal

Definition at line 70 of file sigtyperules.cpp.

References CTree::setType().

Referenced by getInferredType(), and infereRecType().

00071 {
00072     //cerr << "setSigType(" << *sig << ", " << t << ")" << endl;
00073     //setProperty(sig, TYPEPROPERTY, tree((void*)t));
00074     sig->setType(t);
00075 }

Here is the call graph for this function:

Here is the caller graph for this function:

Type T ( Tree  term,
Tree  env 
)

Shortcut to getSigType, retrieve or infere the type of a term according to its surrounding type environment.

Parameters:
sig the signal to analyze
env the type environment
Returns:
the type of sig according to environment env
See also:
getSigType

Definition at line 218 of file sigtyperules.cpp.

References getInferredType().

00219 {
00220     Type t = getInferredType(term, env);
00221     return t;
00222 }

Here is the call graph for this function:

void typeAnnotation ( Tree  sig  ) 

fully annotate every subtree of term with type information

Parameters:
sig the signal term tree to annotate

Definition at line 171 of file sigtyperules.cpp.

References getInferredType().

Referenced by DocCompiler::annotate(), ScalarCompiler::prepare(), and ScalarCompiler::prepare2().

00172 {
00173     getInferredType(sig, NULLENV);
00174 }

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Tree NULLENV = tree(symbol("NullEnv"))

The empty type environment (also property key for closed term type).

Definition at line 106 of file sigtyperules.cpp.

Referenced by docTableConvertion().

Tree TYPEPROPERTY = tree(symbol("TypeProperty"))

Definition at line 63 of file sigtyperules.cpp.

Generated on Thu Jul 15 16:15:50 2010 for FAUST compiler by  doxygen 1.6.3