summaryrefslogtreecommitdiff
path: root/src/types.cpp
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-01-30 21:59:16 +0800
committerJohn Hodge <tpg@mutabah.net>2016-01-30 21:59:16 +0800
commit0b8f4dfa88d392ab188c3ee85e1afe1e3658cca5 (patch)
treef3046716b75c64d263a6826c54c801c7105ecf44 /src/types.cpp
parent3cb317bdb5be06ea0c4ccad8ecb5bb21b74509cc (diff)
downloadmrust-0b8f4dfa88d392ab188c3ee85e1afe1e3658cca5.tar.gz
Better pretty printing, updated resolution logic
Diffstat (limited to 'src/types.cpp')
-rw-r--r--src/types.cpp35
1 files changed, 35 insertions, 0 deletions
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)
{