diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-10-11 15:27:27 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-10-11 15:27:27 -0400 |
| commit | 686150b0cdd4990f020390dbbe52a3dc408cf550 (patch) | |
| tree | c061337132c887f38f287b0626ac0df92b1478af /src | |
| parent | e0a04d4171e03ae64b874b7229d25ce940afa301 (diff) | |
Rename pathtype enum values
Diffstat (limited to 'src')
| -rw-r--r-- | src/compile/optionals.c | 6 | ||||
| -rw-r--r-- | src/environment.c | 6 | ||||
| -rw-r--r-- | src/stdlib/datatypes.h | 2 | ||||
| -rw-r--r-- | src/stdlib/optionals.h | 2 | ||||
| -rw-r--r-- | src/stdlib/paths.c | 48 |
5 files changed, 32 insertions, 32 deletions
diff --git a/src/compile/optionals.c b/src/compile/optionals.c index bd5f861d..c8a7276c 100644 --- a/src/compile/optionals.c +++ b/src/compile/optionals.c @@ -53,7 +53,7 @@ Text_t compile_none(type_t *t) { if (t == NULL) compiler_err(NULL, NULL, NULL, "I can't compile a `none` value with no type"); if (t == PATH_TYPE) return Text("NONE_PATH"); - else if (t == PATH_TYPE_TYPE) return Text("((OptionalPathType_t){.type = PATH_NONE})"); + else if (t == PATH_TYPE_TYPE) return Text("((OptionalPathType_t){.type = PATHTYPE_NONE})"); switch (t->tag) { case BigIntType: return Text("NONE_INT"); @@ -92,8 +92,8 @@ Text_t check_none(type_t *t, Text_t value) { // NOTE: these use statement expressions ({...;}) because some compilers // complain about excessive parens around equality comparisons if (t->tag == PointerType || t->tag == FunctionType || t->tag == CStringType) return Texts("(", value, " == NULL)"); - else if (t == PATH_TYPE) return Texts("((", value, ").type.$tag == PATH_NONE)"); - else if (t == PATH_TYPE_TYPE) return Texts("((", value, ").$tag == PATH_NONE)"); + else if (t == PATH_TYPE) return Texts("((", value, ").type.$tag == PATHTYPE_NONE)"); + else if (t == PATH_TYPE_TYPE) return Texts("((", value, ").$tag == PATHTYPE_NONE)"); else if (t->tag == BigIntType) return Texts("((", value, ").small == 0)"); else if (t->tag == ClosureType) return Texts("((", value, ").fn == NULL)"); else if (t->tag == NumType) diff --git a/src/environment.c b/src/environment.c index 63893788..7d0046de 100644 --- a/src/environment.c +++ b/src/environment.c @@ -290,9 +290,9 @@ env_t *global_env(bool source_mapping) { #undef C MAKE_TYPE( // "PathType", PATH_TYPE_TYPE, Text("PathType_t"), Text("PathType$info"), // - {"Relative", "PATH_RELATIVE", "PathType"}, // - {"Absolute", "PATH_ABSOLUTE", "PathType"}, // - {"Home", "PATH_HOME", "PathType"}), + {"Relative", "PATHTYPE_RELATIVE", "PathType"}, // + {"Absolute", "PATHTYPE_ABSOLUTE", "PathType"}, // + {"Home", "PATHTYPE_HOME", "PathType"}), MAKE_TYPE( // "Path", PATH_TYPE, Text("Path_t"), Text("Path$info"), // {"accessed", "Path$accessed", "func(path:Path, follow_symlinks=yes -> Int64?)"}, // diff --git a/src/stdlib/datatypes.h b/src/stdlib/datatypes.h index dbb321b0..40d9be3e 100644 --- a/src/stdlib/datatypes.h +++ b/src/stdlib/datatypes.h @@ -101,7 +101,7 @@ typedef struct Text_s { }; } Text_t; -typedef enum PathEnum { PATH_NONE, PATH_RELATIVE, PATH_ABSOLUTE, PATH_HOME } PathType_t; +typedef enum PathEnum { PATHTYPE_NONE, PATHTYPE_RELATIVE, PATHTYPE_ABSOLUTE, PATHTYPE_HOME } PathType_t; #define OptionalPathType_t PathType_t typedef struct { diff --git a/src/stdlib/optionals.h b/src/stdlib/optionals.h index 9c875bd1..d067ec94 100644 --- a/src/stdlib/optionals.h +++ b/src/stdlib/optionals.h @@ -15,7 +15,7 @@ #define NONE_TABLE ((OptionalTable_t){.entries.data = NULL}) #define NONE_CLOSURE ((OptionalClosure_t){.fn = NULL}) #define NONE_TEXT ((OptionalText_t){.tag = TEXT_NONE}) -#define NONE_PATH ((Path_t){.type = PATH_NONE}) +#define NONE_PATH ((Path_t){.type = PATHTYPE_NONE}) PUREFUNC bool is_none(const void *obj, const TypeInfo_t *non_optional_type); PUREFUNC uint64_t Optional$hash(const void *obj, const TypeInfo_t *type); diff --git a/src/stdlib/paths.c b/src/stdlib/paths.c index 47ddba54..b6152ed4 100644 --- a/src/stdlib/paths.c +++ b/src/stdlib/paths.c @@ -32,8 +32,8 @@ // Use inline version of the siphash code for performance: #include "siphash-internals.h" -static const Path_t HOME_PATH = {.type = PATH_HOME}, ROOT_PATH = {.type = PATH_ABSOLUTE}, - CURDIR_PATH = {.type = PATH_RELATIVE}; +static const Path_t HOME_PATH = {.type = PATHTYPE_HOME}, ROOT_PATH = {.type = PATHTYPE_ABSOLUTE}, + CURDIR_PATH = {.type = PATHTYPE_RELATIVE}; static void clean_components(List_t *components) { for (int64_t i = 0; i < (int64_t)components->length;) { @@ -64,16 +64,16 @@ Path_t Path$from_str(const char *str) { Path_t result = {.components = {}}; if (str[0] == '/') { - result.type = PATH_ABSOLUTE; + result.type = PATHTYPE_ABSOLUTE; str += 1; } else if (str[0] == '~' && str[1] == '/') { - result.type = PATH_HOME; + result.type = PATHTYPE_HOME; str += 2; } else if (str[0] == '.' && str[1] == '/') { - result.type = PATH_RELATIVE; + result.type = PATHTYPE_RELATIVE; str += 2; } else { - result.type = PATH_RELATIVE; + result.type = PATHTYPE_RELATIVE; } while (str && *str) { @@ -104,12 +104,12 @@ Path_t Path$from_text(Text_t text) { return Path$from_str(Text$as_c_string(text) public Path_t Path$expand_home(Path_t path) { - if (path.type == PATH_HOME) { + if (path.type == PATHTYPE_HOME) { Path_t pwd = Path$from_str(getenv("HOME")); List_t components = List$concat(pwd.components, path.components, sizeof(Text_t)); assert(components.length == path.components.length + pwd.components.length); clean_components(&components); - path = (Path_t){.type = PATH_ABSOLUTE, .components = components}; + path = (Path_t){.type = PATHTYPE_ABSOLUTE, .components = components}; } return path; } @@ -120,7 +120,7 @@ Path_t Path$_concat(int n, Path_t items[n]) { Path_t result = items[0]; LIST_INCREF(result.components); for (int i = 1; i < n; i++) { - if (items[i].type != PATH_RELATIVE) + if (items[i].type != PATHTYPE_RELATIVE) fail("Cannot concatenate an absolute or home-based path onto another path: (", items[i], ")"); List$insert_all(&result.components, items[i].components, I(0), sizeof(Text_t)); } @@ -130,7 +130,7 @@ Path_t Path$_concat(int n, Path_t items[n]) { public Path_t Path$resolved(Path_t path, Path_t relative_to) { - if (path.type == PATH_RELATIVE && !(relative_to.type == PATH_RELATIVE && relative_to.components.length == 0)) { + if (path.type == PATHTYPE_RELATIVE && !(relative_to.type == PATHTYPE_RELATIVE && relative_to.components.length == 0)) { Path_t result = {.type = relative_to.type}; result.components = relative_to.components; LIST_INCREF(result.components); @@ -147,7 +147,7 @@ Path_t Path$relative_to(Path_t path, Path_t relative_to) { fail("Cannot create a path relative to a different path with a mismatching type: (", path, ") relative to (", relative_to, ")"); - Path_t result = {.type = PATH_RELATIVE}; + Path_t result = {.type = PATHTYPE_RELATIVE}; int64_t shared = 0; for (; shared < (int64_t)path.components.length && shared < (int64_t)relative_to.components.length; shared++) { Text_t *p = (Text_t *)(path.components.data + shared * path.components.stride); @@ -558,7 +558,7 @@ Path_t Path$write_unique(Path_t path, Text_t text) { return Path$write_unique_by public Path_t Path$parent(Path_t path) { - if (path.type == PATH_ABSOLUTE && path.components.length == 0) { + if (path.type == PATHTYPE_ABSOLUTE && path.components.length == 0) { return path; } else if (path.components.length > 0 && !Text$equal_values( @@ -577,8 +577,8 @@ public PUREFUNC Text_t Path$base_name(Path_t path) { if (path.components.length >= 1) return *(Text_t *)(path.components.data + path.components.stride * ((int64_t)path.components.length - 1)); - else if (path.type == PATH_HOME) return Text("~"); - else if (path.type == PATH_RELATIVE) return Text("."); + else if (path.type == PATHTYPE_HOME) return Text("~"); + else if (path.type == PATHTYPE_RELATIVE) return Text("."); else return EMPTY_TEXT; } @@ -765,17 +765,17 @@ PUREFUNC bool Path$equal_values(Path_t a, Path_t b) { public int Path$print(FILE *f, Path_t path) { if (path.components.length == 0) { - if (path.type == PATH_ABSOLUTE) return fputs("/", f); - else if (path.type == PATH_RELATIVE) return fputs(".", f); - else if (path.type == PATH_HOME) return fputs("~", f); + if (path.type == PATHTYPE_ABSOLUTE) return fputs("/", f); + else if (path.type == PATHTYPE_RELATIVE) return fputs(".", f); + else if (path.type == PATHTYPE_HOME) return fputs("~", f); } int n = 0; - if (path.type == PATH_ABSOLUTE) { + if (path.type == PATHTYPE_ABSOLUTE) { n += fputc('/', f); - } else if (path.type == PATH_HOME) { + } else if (path.type == PATHTYPE_HOME) { n += fputs("~/", f); - } else if (path.type == PATH_RELATIVE) { + } else if (path.type == PATHTYPE_RELATIVE) { if (!Text$equal_values(*(Text_t *)path.components.data, Text(".."))) n += fputs("./", f); } @@ -796,9 +796,9 @@ Text_t Path$as_text(const void *obj, bool color, const TypeInfo_t *type) { if (!obj) return Text("Path"); Path_t *path = (Path_t *)obj; Text_t text = Text$join(Text("/"), path->components); - if (path->type == PATH_HOME) text = Text$concat(path->components.length > 0 ? Text("~/") : Text("~"), text); - else if (path->type == PATH_ABSOLUTE) text = Text$concat(Text("/"), text); - else if (path->type == PATH_RELATIVE + if (path->type == PATHTYPE_HOME) text = Text$concat(path->components.length > 0 ? Text("~/") : Text("~"), text); + else if (path->type == PATHTYPE_ABSOLUTE) text = Text$concat(Text("/"), text); + else if (path->type == PATHTYPE_RELATIVE && (path->components.length == 0 || !Text$equal_values(*(Text_t *)(path->components.data), Text("..")))) text = Text$concat(path->components.length > 0 ? Text("./") : Text("."), text); @@ -810,7 +810,7 @@ Text_t Path$as_text(const void *obj, bool color, const TypeInfo_t *type) { public CONSTFUNC bool Path$is_none(const void *obj, const TypeInfo_t *type) { (void)type; - return ((Path_t *)obj)->type == PATH_NONE; + return ((Path_t *)obj)->type == PATHTYPE_NONE; } public |
