00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __EX_Func_h__
00022 #define __EX_Func_h__
00023
00024 #include "EXPR_API.h"
00025 #include <iostream.h>
00026 #include <UT/UT_IntArray.h>
00027 #include <UT/UT_PtrArray.h>
00028 #include "EXPR.h"
00029
00030 class EX_Stream;
00031 class EX_Token;
00032 class EX_Function;
00033
00034 class EXPR_API EX_Symbol {
00035 public:
00036
00037 EX_Symbol(const char *name, int type, int thread);
00038 ~EX_Symbol();
00039
00040 int myFlag;
00041 UT_String myName;
00042 EV_SYMBOL *mySym;
00043 EX_Symbol *myNext;
00044 };
00045
00046 class EXPR_API EX_ExprLine {
00047 public:
00048 EX_ExprLine();
00049 ~EX_ExprLine();
00050
00051 bool saveCompiled(ostream &os);
00052 bool loadCompiled(UT_IStream &is);
00053
00054 void setExpression(const char *source);
00055
00056 int myFlag;
00057 int myLineNum;
00058 int myOperand;
00059 EX_Symbol *mySymbols;
00060 EV_EXPRESSION *myExpr;
00061 EX_ExprLine *myBranch;
00062 EX_ExprLine *myNext;
00063 int myBranchNum;
00064 };
00065
00066 class EXPR_API EX_ExprFunc {
00067 public:
00068 EX_ExprFunc();
00069 ~EX_ExprFunc();
00070
00071
00072
00073
00074 int save(ostream &os);
00075 bool saveCompiled(ostream &os, int thread);
00076 bool load(UT_IStream &is, const char *filename, ostream *err,
00077 int thread);
00078 bool loadCompiled(UT_IStream &is, int thread);
00079
00080
00081 void wire();
00082
00083 const char *getName() const { return myName; }
00084 int getNArgs() const { return myArgTypes.entries(); }
00085 const char *getReturnType() const;
00086 const char *getArgName(int i);
00087 const char *getArgType(int i);
00088
00089 void touchMyReferences();
00090 void functionDeleted(EV_EXPRESSION *expr);
00091
00092 void updateDependency(void *ref_id, int thread);
00093 int changeOpReference(UT_String &new_source,
00094 const EV_ChangeOpReferenceParms &parms,
00095 int thread);
00096
00097 void setInlineFlag(bool f) { myInlineFlag = f; }
00098 bool getInlineFlag() const { return myInlineFlag; }
00099
00100 int getRunningCount() const { return myRunningCount; }
00101
00102 void unresolveLocalVars(int thread);
00103
00104 private:
00105 void unwire();
00106
00107 void errorMessage(const char *fmt, int linenum = -1,
00108 const char *a1=0, const char *a2=0);
00109
00110
00111 int getLastLineNum() const;
00112 int checkValidName(const char *name);
00113 int checkType(const char *name);
00114 EX_Symbol *symbolExists(const char *name);
00115 EX_Symbol *addToSymbolTable(const char *name, int type, bool exists,
00116 int thread);
00117 void addLineToExpr(EX_ExprLine *line);
00118 int addLoopBranch(int linenum);
00119 void resolveBreakCont(EX_ExprLine *line, int brk, int cont);
00120 int getAssignment(EX_ExprLine *, EX_Stream &, EX_Token *, int eol,
00121 int thread);
00122 int doForLine(EX_ExprLine *line, EX_Stream &is, int thread);
00123 int doWhileLine(EX_ExprLine *line, EX_Stream &is, int thread);
00124 int doIfLine(EX_ExprLine *line, EX_Stream &is, int thread);
00125 int doBreakLine(EX_ExprLine *line, EX_Stream &is, int);
00126 int doReturnLine(EX_ExprLine *line, EX_Stream &is);
00127 int addReturn0();
00128 int parseLine(EX_Stream &is, int thread);
00129 int resolveBranches();
00130 int parseFunction(EX_Stream &is, int thread);
00131
00132 int getScopeNest(EX_Stream &is, int thread);
00133
00134 void internalEvaluate(EV_SYMBOL *result, EV_SYMBOL **argv,
00135 int thread);
00136 static void evaluate(EV_FUNCTION *, EV_SYMBOL *result, EV_SYMBOL **argv,
00137 int thread);
00138
00139
00140 int load(EX_Stream &xis, const char *filename, ostream *err,
00141 int thread);
00142
00143 UT_String myName;
00144 UT_String mySourceFile;
00145 UT_IntArray myArgTypes;
00146 int myResultType;
00147 UT_String mySource;
00148 ostream *myError;
00149
00150 bool myInlineFlag;
00151 int myRunningCount;
00152
00153
00154 EX_Symbol *mySymbols;
00155 EX_ExprLine *myLines;
00156 EX_ExprLine *myLastLine;
00157 EX_Function *myTableEntry;
00158 UT_PtrArray<EV_EXPRESSION *> myReferences;
00159 };
00160
00161 #endif