Created
December 3, 2009 21:04
-
-
Save agustingianni/248520 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <ostream> | |
#include <sstream> | |
#include <iostream> | |
using namespace std; | |
enum SymbolType | |
{ | |
SYMBOL_TYPE_NONE, | |
SYMBOL_TYPE_DATA, | |
SYMBOL_TYPE_CODE | |
}; | |
enum SymbolBinding | |
{ | |
SYMBOL_BINDING_NONE, | |
SYMBOL_BINDING_LOCAL, | |
SYMBOL_BINDING_GLOBAL, | |
SYMBOL_BINDING_WEAK | |
}; | |
class Symbol | |
{ | |
private: | |
string name; | |
SymbolType type; | |
SymbolBinding binding; | |
unsigned int value; | |
public: | |
Symbol(const char *name, unsigned int value, SymbolType type, SymbolBinding binding); | |
Symbol(string name, unsigned int value, SymbolType type, SymbolBinding binding); | |
virtual ~Symbol() {} | |
SymbolBinding getBinding() const; | |
string getName() const; | |
SymbolType getType() const; | |
unsigned int getValue() const; | |
void setBinding(SymbolBinding binding); | |
void setName(string name); | |
void setType(SymbolType type); | |
void setValue(unsigned int value); | |
friend ostream &operator<< (ostream &s, Symbol &symbol); | |
}; | |
Symbol::Symbol(const char *name, unsigned int value, SymbolType type, | |
SymbolBinding binding) | |
{ | |
stringstream ss; | |
ss << name; | |
Symbol(ss.str(), value, type, binding); | |
} | |
Symbol::Symbol(string name, unsigned int value, SymbolType type, | |
SymbolBinding binding) | |
{ | |
this->name = name; | |
this->value = value; | |
this->type = type; | |
this->binding = binding; | |
} | |
SymbolBinding Symbol::getBinding() const | |
{ | |
return binding; | |
} | |
string Symbol::getName() const | |
{ | |
return name; | |
} | |
SymbolType Symbol::getType() const | |
{ | |
return type; | |
} | |
unsigned int Symbol::getValue() const | |
{ | |
return value; | |
} | |
void Symbol::setBinding(SymbolBinding binding) | |
{ | |
this->binding = binding; | |
} | |
void Symbol::setName(string name) | |
{ | |
this->name = name; | |
} | |
void Symbol::setType(SymbolType type) | |
{ | |
this->type = type; | |
} | |
void Symbol::setValue(unsigned int value) | |
{ | |
this->value = value; | |
} | |
ostream &operator<<(ostream &s, const Symbol &p) | |
{ | |
s << "<" << p.getName() << ", " << (void *) p.getValue() << ">"; | |
return s; | |
} | |
int | |
main(int argc, char **argv) | |
{ | |
Symbol *s = new Symbol("Pepe", 0x31337, SYMBOL_TYPE_CODE, SYMBOL_BINDING_GLOBAL); | |
cout << s << "\n"; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment