]> ocean-lang.org Git - ocean/commitdiff
oceani: replace some magic numbers with an enum.
authorNeilBrown <neil@brown.name>
Sat, 11 Dec 2021 22:43:41 +0000 (09:43 +1100)
committerNeilBrown <neil@brown.name>
Sat, 11 Dec 2021 22:43:41 +0000 (09:43 +1100)
I'm growing to dislike magic numbers

Signed-off-by: NeilBrown <neil@brown.name>
csrc/oceani.mdc

index 12be60cff7e066d9cfc9bf032047510a8701976d..178532c07a9c1a17d6c2baf788c381fbd533cc9d 100644 (file)
@@ -2742,6 +2742,7 @@ function will be needed.
                int index;
                struct text name;
        };
+       enum { IndexUnknown = -1, IndexInvalid = -2 };
 
 ###### free exec cases
        case Xfieldref:
@@ -2758,7 +2759,7 @@ function will be needed.
                struct fieldref *fr = new_pos(fieldref, $2);
                fr->left = $<1;
                fr->name = $3.txt;
-               fr->index = -2;
+               fr->index = IndexUnknown;
                $0 = fr;
        } }$
 
@@ -2779,7 +2780,7 @@ function will be needed.
                for (i = 0; i < type->structure.nfields; i++)
                        if (text_cmp(type->structure.fields[i].name, field) == 0)
                                return i;
-               return -1;
+               return IndexInvalid;
        }
 
 ###### propagate exec cases
@@ -2795,7 +2796,7 @@ function will be needed.
                else if (st->init != structure_init)
                        type_err(c, "error: field reference attempted on %1, not a struct",
                                 f->left, st, 0, NULL);
-               else if (f->index == -2) {
+               else if (f->index == IndexUnknown) {
                        f->index = find_struct_index(st, f->name);
                        if (f->index < 0)
                                type_err(c, "error: cannot find requested field in %1",