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; return RETURN;
} }
"Necchi" { "Necchi" {
monicelli_lval.typeval = TYPENAME_INT; monicelli_lval.typeval = Type::INT;
return TYPENAME; return TYPENAME;
} }
"Mascetti" { "Mascetti" {
monicelli_lval.typeval = TYPENAME_CHAR; monicelli_lval.typeval = Type::CHAR;
return TYPENAME; return TYPENAME;
} }
"Perozzi" { "Perozzi" {
monicelli_lval.typeval = TYPENAME_FLOAT; monicelli_lval.typeval = Type::FLOAT;
return TYPENAME; return TYPENAME;
} }
"Melandri" { "Melandri" {
monicelli_lval.typeval = TYPENAME_BOOL; monicelli_lval.typeval = Type::BOOL;
return TYPENAME; return TYPENAME;
} }
"Sassaroli" { "Sassaroli" {
monicelli_lval.typeval = TYPENAME_DOUBLE; monicelli_lval.typeval = Type::DOUBLE;
return TYPENAME; return TYPENAME;
} }
"conte" { "conte" {

View File

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

View File

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