From 83445588fd6b61e9b48a5c1a074328fa2b7e088b Mon Sep 17 00:00:00 2001 From: Joshua Weinstein Date: Sun, 3 Jun 2018 00:44:12 -0700 Subject: [PATCH] new type error scheme --- include/WindType.h | 4 +--- src/code/WindType.c | 24 ++++++++++++++++++++++++ src/flow/WindComp.c | 4 ++-- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/include/WindType.h b/include/WindType.h index 694e20f..ead518b 100644 --- a/include/WindType.h +++ b/include/WindType.h @@ -25,8 +25,6 @@ typedef enum WindCommand_map } WindCommand; -/*Literal String represenations for windtype*/ -extern const char* WindType_STR_NONE; -extern const char* WindType_STR_BOOL; +const char* WindType_get_str(WindType type); #endif diff --git a/src/code/WindType.c b/src/code/WindType.c index 6c0e22a..d2b3179 100644 --- a/src/code/WindType.c +++ b/src/code/WindType.c @@ -1 +1,25 @@ #include "WindType.h" + + +/*Strings for type message formatting*/ +static const char* WindType_STR_NONE = "None"; +static const char* WindType_STR_BOOL = "Bool"; +static const char* WindType_STR_NUMBER = "Number"; +static const char* WindType_STR_ASSIGN = "Assign"; +static const char* WindType_STR_NOT = "Not"; +static const char* WindType_STR_PLUS = "Plus"; +static const char* WindType_STR_SEP = "Separator"; + +const char* WindType_get_str(WindType type) +{ + switch(type) + { + case WindType_None: return WindType_STR_NONE; + case WindType_Bool: return WindType_STR_BOOL; + case WindType_Not: return WindType_STR_NOT; + case WindType_Number: return WindType_STR_NUMBER; + case WindType_Assign: return WindType_STR_ASSIGN; + case WindType_Plus: return WindType_STR_PLUS; + case WindType_Sep: return WindType_STR_SEP; + } +} diff --git a/src/flow/WindComp.c b/src/flow/WindComp.c index 095aaf3..f94fb15 100644 --- a/src/flow/WindComp.c +++ b/src/flow/WindComp.c @@ -104,7 +104,7 @@ unsigned WindComp_apply_plus(unsigned char* args, const unsigned char* argsEnd) { if(WindComp_BUF[0] != WindType_Number) { - WindState_write_err("Attempted to use + operator on type that is not number."); + WindState_write_err("Attempted to use + operator on type: '%s'", WindType_get_str(WindComp_BUF[0])); return 0; } unsigned char* mover = args; @@ -125,7 +125,7 @@ unsigned WindComp_apply_plus(unsigned char* args, const unsigned char* argsEnd) case WindType_Sep: return mover - args; default: - WindState_write_err("Attempted to use + operator on arg with non-number type: %u", *mover); + WindState_write_err("Attempted to use + operator on arg with type: '%s'", WindType_get_str(*mover)); return 0; } }