00001
00002 #ifndef VARIABLE_H_
00003 #define VARIABLE_H_
00004
00005 #include <string>
00006 #include <iostream>
00007
00008 #include <boost/serialization/string.hpp>
00009 #include <boost/serialization/version.hpp>
00010 #include <boost/serialization/split_member.hpp>
00011 #include <boost/serialization/shared_ptr.hpp>
00012 #include <boost/serialization/base_object.hpp>
00013 #include <boost/serialization/export.hpp>
00014 #include <boost/serialization/set.hpp>
00015
00016 #include "type.h"
00017 #include "namespace_context.h"
00018
00019 using namespace std;
00020
00021
00022
00023
00024 namespace il
00025 {
00026 class type;
00027 enum qualifier_type {NONE = 0, EXTERN = 1, VOLATILE = 2, STATIC = 4,
00028 REGISTER = 8, CONSTANT = 16, PRIVATE = 32, PUBLIC=64,
00029 PROTECTED=128};
00030
00031 string qt_to_string(qualifier_type qt);
00032
00033
00034
00035 enum scope_type {GLOBAL, ARGUMENT, LOCAL};
00036
00037 class variable_declaration;
00038 class block;
00039
00043 class variable
00044 {
00045 friend class boost::serialization::access;
00046
00047 template<class Archive>
00048 void save(Archive & ar, const unsigned int version) const
00049 {
00050 ar & name;
00051 ar & ns;
00052 ar & scope;
00053 ar & qt;
00054 ar & decl;
00055 ar & t;
00056 ar & st;
00057 ar & arg_num;
00058 }
00059
00060 template<class Archive>
00061 void load(Archive & ar, const unsigned int version)
00062 {
00063 ar & name;
00064 ar & ns;
00065 ar & scope;
00066 ar & qt;
00067 ar & decl;
00068 ar & t;
00069 type::register_loaded_typeref(&t);
00070 ar & st;
00071 ar & arg_num;
00072 }
00073
00074 BOOST_SERIALIZATION_SPLIT_MEMBER()
00075
00076
00077 private:
00078
00079 static int unmodeled_counter;
00080 string name;
00081 namespace_context ns;
00082 block *scope;
00083 qualifier_type qt;
00084 variable_declaration *decl;
00085 type* t;
00086 scope_type st;
00087 int arg_num;
00088
00089
00090 public:
00091
00092 static variable* get_unmodeled_var();
00093
00094 friend ostream& operator <<(ostream &os, const variable &obj);
00095 variable();
00096 variable(string name, namespace_context ns,
00097 block *scope, scope_type st, qualifier_type qt,
00098 variable_declaration* decl, type* t, int i=-1);
00099
00100 bool is_global();
00101 bool is_local();
00102 bool is_argument();
00103 void set_declaration(variable_declaration *vd){decl = vd;};
00104 virtual string to_string() const;
00105 void set_scope(block *b);
00106 int get_arg_num();
00107 variable_declaration* get_declaration(){return decl;}
00108
00109
00110
00111
00112 block *get_scope();
00113 scope_type get_scope_type();
00114 type* get_type(){return t;};
00115 string get_name();
00116 const namespace_context& get_namespace() const;
00117 void print();
00118 bool operator==(const variable & other);
00119 ~variable();
00120 bool is_extern(){return qt & EXTERN;};
00121 bool is_volatile(){return qt & VOLATILE;};
00122 bool is_static(){return qt & STATIC;};
00123 bool is_register(){return qt & REGISTER;};
00124 bool is_constant(){return qt & CONSTANT;};
00125 bool is_private(){return qt & PRIVATE;};
00126 bool is_protected(){return qt & PROTECTED;};
00127 bool is_public(){return qt & PUBLIC;};
00128 };
00129
00130 }
00131
00132 #endif