diff lwasm/section.c @ 370:8764142b3192

Convert internal error/warning handling framework to a new unified system Replace the ad hoc error and warning handling with a new system that codifies the errors with specific codes. This makes it possible in the future for error numbers to be used for testing and other purposes. It also makes sure the error strings themselves are consistent. Thanks to Erik G <erik@6809.org> for the patch.
author William Astle <lost@l-w.ca>
date Mon, 22 Jun 2015 18:49:38 -0600
parents 35f7ce3ef857
children 58cafa61ab40
line wrap: on
line diff
--- a/lwasm/section.c	Mon Jun 22 18:38:30 2015 -0600
+++ b/lwasm/section.c	Mon Jun 22 18:49:38 2015 -0600
@@ -37,13 +37,13 @@
 
 	if (as -> output_format != OUTPUT_OBJ)
 	{
-		lwasm_register_error(as, l, "Cannot use sections unless using the object target");
+		lwasm_register_error(as, l, E_SECTION_TARGET);
 		return;
 	}
 	
 	if (!**p)
 	{
-		lwasm_register_error(as, l, "Need section name");
+		lwasm_register_error(as, l, E_SECTION_NAME);
 		return;
 	}
 
@@ -81,7 +81,7 @@
 	}
 	if (s && opts)
 	{
-		lwasm_register_warning(as, l, "Section flags can only be specified the first time; ignoring duplicate definition");
+		lwasm_register_error(as, l, W_DUPLICATE_SECTION);
 	}
 	if (!s)
 	{
@@ -125,7 +125,7 @@
 			}
 			else
 			{
-				lwasm_register_error(as, l, "Unrecognized section flag");
+				lwasm_register_error(as, l, E_SECTION_FLAG);
 				lw_free(sn);
 				lw_free(opts);
 				lw_free(s -> name);
@@ -158,7 +158,7 @@
 {
 	if (as -> output_format != OUTPUT_OBJ)
 	{
-		lwasm_register_error(as, l, "Cannot use sections unless using the object target");
+		lwasm_register_error(as, l, E_SECTION_TARGET);
 		return;
 	}
 
@@ -166,7 +166,7 @@
 
 	if (!(as -> csect))
 	{
-		lwasm_register_error(as, l, "ENDSECTION without SECTION");
+		lwasm_register_error(as, l, E_SECTION_END);
 		return;
 	}
 
@@ -192,7 +192,7 @@
 	
 	if (as -> output_format != OUTPUT_OBJ)
 	{
-		lwasm_register_error(as, l, "EXPORT only supported for object target");
+		lwasm_register_error2(as, l, E_OBJTARGET_ONLY, "(%s)", "EXPORT");
 		return;
 	}
 
@@ -223,7 +223,7 @@
 	}
 	if (!sym)
 	{
-		lwasm_register_error(as, l, "No symbol for EXPORT");
+		lwasm_register_error2(as, l, E_SYMBOL_MISSING, "for %s", "EXPORT");
 		return;
 	}
 	
@@ -254,7 +254,7 @@
 	
 	if (as -> output_format != OUTPUT_OBJ)
 	{
-		lwasm_register_error(as, l, "IMPORT only supported for object target");
+		lwasm_register_error2(as, l, E_OBJTARGET_ONLY, "(%s)", "IMPORT");
 		return;
 	}
 	
@@ -285,7 +285,7 @@
 	}
 	if (!sym)
 	{
-		lwasm_register_error(as, l, "No symbol for IMPORT");
+		lwasm_register_error2(as, l, E_SYMBOL_MISSING, "for %s", "IMPORT");
 		return;
 	}
 	
@@ -314,13 +314,13 @@
 	
 	if (as -> output_format != OUTPUT_OBJ)
 	{
-		lwasm_register_error(as, l, "EXTDEP only supported for object target");
+		lwasm_register_error2(as, l, E_OBJTARGET_ONLY, "(%s)", "EXTDEP");
 		return;
 	}
 	
 	if (!as -> csect)
 	{
-		lwasm_register_error(as, l, "EXTDEP must be within a section");
+		lwasm_register_error(as, l, E_SECTION_EXTDEP);
 		return;
 	}
 	
@@ -347,7 +347,7 @@
 	}
 	if (!sym)
 	{
-		lwasm_register_error(as, l, "No symbol for EXTDEP");
+		lwasm_register_error2(as, l, E_SYMBOL_MISSING, "for %s", "EXTDEP");
 		return;
 	}