From 0b8f4dfa88d392ab188c3ee85e1afe1e3658cca5 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 30 Jan 2016 21:59:16 +0800 Subject: Better pretty printing, updated resolution logic --- src/types.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/types.cpp') diff --git a/src/types.cpp b/src/types.cpp index 7e2a835e..882caef5 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -10,6 +10,41 @@ #include "types.hpp" #include "ast/ast.hpp" +/// Mappings from internal type names to the core type enum +static const struct { + const char* name; + enum eCoreType type; +} CORETYPES[] = { + {"bool", CORETYPE_BOOL}, + {"char", CORETYPE_CHAR}, + {"f32", CORETYPE_F32}, + {"f64", CORETYPE_F64}, + {"i16", CORETYPE_I16}, + {"i32", CORETYPE_I32}, + {"i64", CORETYPE_I64}, + {"i8", CORETYPE_I8}, + {"int", CORETYPE_INT}, + {"isize", CORETYPE_INT}, + {"u16", CORETYPE_U16}, + {"u32", CORETYPE_U32}, + {"u64", CORETYPE_U64}, + {"u8", CORETYPE_U8}, + {"uint", CORETYPE_UINT}, + {"usize", CORETYPE_UINT}, +}; + +enum eCoreType coretype_fromstring(const ::std::string& name) +{ + for(unsigned int i = 0; i < sizeof(CORETYPES)/sizeof(CORETYPES[0]); i ++) + { + if( name < CORETYPES[i].name ) + break; + if( name == CORETYPES[i].name ) + return CORETYPES[i].type; + } + return CORETYPE_INVAL; +} + const char* coretype_name(const eCoreType ct ) { switch(ct) { -- cgit v1.2.3