FAUST compiler  0.9.9.6b8
binop.hh
Go to the documentation of this file.
00001 /************************************************************************
00002  ************************************************************************
00003     FAUST compiler
00004     Copyright (C) 2003-2004 GRAME, Centre National de Creation Musicale
00005     ---------------------------------------------------------------------
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  ************************************************************************
00020  ************************************************************************/
00021  
00022  
00023  
00024 #ifndef _BINOP_
00025 #define _BINOP_
00026 
00027 #include "node.hh"
00028 
00029 typedef const Node  (*comp) (const Node& a, const Node& b);
00030 typedef bool        (*pred) (const Node& a);
00031 
00032 struct BinOp 
00033 {
00034     const char* fName;
00035     const char* fNameVec;
00036     const char* fNameScal;
00037     comp        fCompute;
00038     pred        fLeftNeutral;
00039     pred        fRightNeutral;
00040     int         fPriority;
00041     //
00042     BinOp (const char* name, const char* namevec, const char* namescal, comp f, pred ln, pred rn, int priority) 
00043             : fName(name), fNameVec(namevec), fNameScal(namescal), fCompute(f), fLeftNeutral(ln), fRightNeutral(rn), fPriority(priority) {  }
00044     //
00045     Node compute(const Node& a, const Node& b) { return fCompute(a,b);  }
00046     //
00047     bool isRightNeutral(const Node& a)  { return fRightNeutral(a);  }
00048     bool isLeftNeutral(const Node& a)   { return fLeftNeutral(a);   }
00049 };
00050 
00051 extern BinOp* gBinOpTable[];
00052 extern BinOp* gBinOpLateqTable[];
00053 
00054 
00055 enum {
00056     kAdd, kSub, kMul, kDiv, kRem,
00057     kLsh, kRsh,
00058     kGT, kLT, kGE, kLE, kEQ, kNE,
00059     kAND, kOR, kXOR
00060 };
00061 
00062 #endif