00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef INCL_UCSYM
00026 #define INCL_UCSYM
00027
00028 #ifdef HAVE_CONFIG_H
00029 # include <config.h>
00030 #endif
00031
00032 #include <string>
00033 #include <map>
00034 #include <vector>
00035 using std::vector;
00036
00037 class Uc_array_expression;
00038 class Uc_expression;
00039 class Uc_function;
00040
00041
00042
00043
00044 class String_compare
00045 {
00046 public:
00047 bool operator()(char * const &x, char * const &y) const;
00048 };
00049
00050
00051
00052
00053 class Uc_symbol
00054 {
00055 protected:
00056 std::string name;
00057 public:
00058 friend class Uc_scope;
00059 Uc_symbol(char *nm) : name(nm)
00060 { }
00061 const char *get_name() { return name.c_str(); }
00062
00063 virtual int gen_value(vector<char>& out);
00064
00065 virtual int gen_assign(vector<char>& out);
00066
00067 virtual int gen_call(vector<char>& out, Uc_function *fun, bool orig,
00068 Uc_expression *item, Uc_array_expression *parms,
00069 bool retvalue);
00070 virtual int get_string_offset()
00071 { return -1; }
00072
00073 virtual Uc_expression *create_expression();
00074 };
00075
00076
00077
00078
00079 class Uc_var_symbol : public Uc_symbol
00080 {
00081 protected:
00082 int offset;
00083
00084 public:
00085 friend class Uc_scope;
00086 Uc_var_symbol(char *nm, int off) : Uc_symbol(nm), offset(off)
00087 { }
00088 int get_offset()
00089 { return offset; }
00090
00091 virtual int gen_value(vector<char>& out);
00092
00093 virtual int gen_assign(vector<char>& out);
00094
00095 virtual Uc_expression *create_expression();
00096 };
00097
00098
00099
00100
00101 class Uc_static_var_symbol : public Uc_var_symbol
00102 {
00103 public:
00104 Uc_static_var_symbol(char *nm, int off) : Uc_var_symbol(nm, offset)
00105 { }
00106
00107 virtual int gen_value(vector<char>& out);
00108
00109 virtual int gen_assign(vector<char>& out);
00110 };
00111
00112
00113
00114
00115 class Uc_const_int_symbol : public Uc_symbol
00116 {
00117 int value;
00118 public:
00119 Uc_const_int_symbol(char *nm, int v) : Uc_symbol(nm), value(v)
00120 { }
00121
00122 virtual int gen_value(vector<char>& out);
00123
00124 virtual Uc_expression *create_expression();
00125 int get_value() const
00126 { return value; }
00127 };
00128
00129
00130
00131
00132
00133 class Uc_string_symbol : public Uc_symbol
00134 {
00135 int offset;
00136 public:
00137 Uc_string_symbol(char *nm, int off) : Uc_symbol(nm), offset(off)
00138 { }
00139
00140 virtual int gen_value(vector<char>& out);
00141 virtual int get_string_offset()
00142 { return offset; }
00143
00144 virtual Uc_expression *create_expression();
00145 };
00146
00147
00148
00149
00150 class Uc_intrinsic_symbol : public Uc_symbol
00151 {
00152 int intrinsic_num;
00153 int num_parms;
00154 public:
00155 Uc_intrinsic_symbol(char *nm, int n) : Uc_symbol(nm), intrinsic_num(n),
00156 num_parms(0)
00157 { }
00158 int get_intrinsic_num()
00159 { return intrinsic_num; }
00160 int get_num_parms()
00161 { return num_parms; }
00162
00163 virtual int gen_call(vector<char>& out, Uc_function *fun, bool orig,
00164 Uc_expression *item, Uc_array_expression *parms,
00165 bool retvalue);
00166 };
00167
00168
00169
00170
00171 class Uc_function_symbol : public Uc_symbol
00172 {
00173 static int last_num;
00174
00175 public:
00176
00177 typedef std::map<int, Uc_symbol *> Sym_nums;
00178 private:
00179 static Sym_nums nums_used;
00180
00181 std::vector<char *> parms;
00182 int usecode_num;
00183 public:
00184 Uc_function_symbol(char *nm, int num, std::vector<char *>& p);
00185 const std::vector<char *>& get_parms()
00186 { return parms; }
00187 int get_usecode_num()
00188 { return usecode_num; }
00189 int get_num_parms()
00190 { return parms.size(); }
00191
00192 virtual int gen_call(vector<char>& out, Uc_function *fun, bool orig,
00193 Uc_expression *item, Uc_array_expression *parms,
00194 bool retvalue);
00195 };
00196
00197
00198
00199
00200 class Uc_scope
00201 {
00202 Uc_scope *parent;
00203
00204 typedef std::map<char *, Uc_symbol *, String_compare> Sym_map;
00205 Sym_map symbols;
00206 std::vector<Uc_scope *> scopes;
00207 public:
00208 Uc_scope(Uc_scope *p) : parent(p)
00209 { }
00210 ~Uc_scope();
00211 Uc_scope *get_parent()
00212 { return parent; }
00213 Uc_symbol *search(const char *nm)
00214 {
00215 char *nm1 = (char *) nm;
00216 Sym_map::const_iterator it = symbols.find(nm1);
00217 if (it == symbols.end())
00218 return 0;
00219 else
00220 return (*it).second;
00221 }
00222
00223 Uc_symbol *search_up(char *nm);
00224 void add(Uc_symbol *sym)
00225 {
00226 const char *nm = sym->name.c_str();
00227 char *nm1 = (char *)nm;
00228 symbols[nm1] = sym;
00229 }
00230 Uc_scope *add_scope()
00231 {
00232 Uc_scope *newscope = new Uc_scope(this);
00233 scopes.push_back(newscope);
00234 return newscope;
00235 }
00236
00237 int add_function_symbol(Uc_function_symbol *fun);
00238 };
00239
00240 #endif
00241
00242