Strongly typed enum for type tokens.

This commit is contained in:
Stefano Sanfilippo 2014-11-27 21:53:25 +01:00
parent 76ee587672
commit ce513643da
3 changed files with 17 additions and 17 deletions

View File

@ -37,23 +37,23 @@ CHAR [a-zA-Z_]
return RETURN;
}
"Necchi" {
monicelli_lval.typeval = TYPENAME_INT;
monicelli_lval.typeval = Type::INT;
return TYPENAME;
}
"Mascetti" {
monicelli_lval.typeval = TYPENAME_CHAR;
monicelli_lval.typeval = Type::CHAR;
return TYPENAME;
}
"Perozzi" {
monicelli_lval.typeval = TYPENAME_FLOAT;
monicelli_lval.typeval = Type::FLOAT;
return TYPENAME;
}
"Melandri" {
monicelli_lval.typeval = TYPENAME_BOOL;
monicelli_lval.typeval = Type::BOOL;
return TYPENAME;
}
"Sassaroli" {
monicelli_lval.typeval = TYPENAME_DOUBLE;
monicelli_lval.typeval = Type::DOUBLE;
return TYPENAME;
}
"conte" {

View File

@ -97,19 +97,19 @@ void Branch::emit(std::ostream &stream, int indent) {
void VarDeclaration::emit(std::ostream &stream, int indent) {
switch (type) {
case TYPENAME_INT:
case Type::INT:
stream << "int";
break;
case TYPENAME_CHAR:
case Type::CHAR:
stream << "char";
break;
case TYPENAME_FLOAT:
case Type::FLOAT:
stream << "float";
break;
case TYPENAME_BOOL:
case Type::BOOL:
stream << "bool";
break;
case TYPENAME_DOUBLE:
case Type::DOUBLE:
stream << "double";
break;
}

View File

@ -7,13 +7,13 @@
namespace monicelli {
typedef enum {
TYPENAME_INT,
TYPENAME_CHAR,
TYPENAME_FLOAT,
TYPENAME_BOOL,
TYPENAME_DOUBLE
} Type;
enum class Type {
INT,
CHAR,
FLOAT,
BOOL,
DOUBLE
};
class Emittable {