Files
waozi ecdec69f5b
Publish website / build (push) Failing after 24m46s
Publish website / deploy (push) Skipped
Build check / check (push) Canceled after 0s
Preserve imported enum constants in native exports
Resolve the full qualified enum type and its declaring owner in the C and Go text resolvers. Imported and publicly re-exported unique enum values retain their named constants on repeated export and recovery.

Validation: focused native C and Go cases with imports, re-exports, negative and duplicate values; the 21-file recovered Go runtime compiles and preserves imported member references. Full local suite: 272 actual retained checks, zero reused or failed. All 95 bootstrap roots reproduce with stage-2 and independent verification.
2026-12-04 00:13:51 -03:00

767 lines
31 KiB
C

/* Generated by zi2c from compiler_statement.zi. */
#include <stdbool.h>
#include "zir_string.h"
#include "compiler_statement.h"
#include "ziran_compiler.h"
static bool compiler_statement_CompilePrefix(String source, String prefix) ZIRAN_MAYBE_UNUSED;
static String compiler_statement_Trim(String source) ZIRAN_MAYBE_UNUSED;
static bool compiler_statement_Name(String source, int64_t limit) ZIRAN_MAYBE_UNUSED;
static String compiler_statement_HeaderBody(String source, String keyword, int64_t limit) ZIRAN_MAYBE_UNUSED;
static int64_t compiler_statement_AfterQuote(String source, int64_t start) ZIRAN_MAYBE_UNUSED;
static int64_t compiler_statement_FindByte(String source, uint8_t wanted) ZIRAN_MAYBE_UNUSED;
ControlLine
compiler_statement_SplitControlLine(String source)
{
ControlLine result = {0};
String* value_0 = &(result.header);
(*value_0) = source;
int64_t condition = -1LL;
if (compiler_source_StartsWord(source, StringLiteral("if"))) {
condition = compiler_text_SkipSpace(source, 2LL, true);
} else if (compiler_source_StartsWord(source, StringLiteral("else"))) {
int64_t after_else = compiler_text_SkipSpace(source, 4LL, true);
if (compiler_source_StartsWord(StringRangeAt(source, (int64_t)after_else, (int64_t)source.length), StringLiteral("if"))) {
condition = compiler_text_SkipSpace(source, (int64_t)((uint64_t)after_else + UINT64_C(2)), true);
}
}
if (condition >= 0LL) {
int32_t parens = 0;
int32_t brackets = 0;
int32_t braces = 0;
int64_t at = condition;
String previous = StringLiteral("");
while (at < (int64_t)(source).length) {
Scan token = compiler_scan_NextToken(source, at, 1, 1);
if (((TokenKind)(token.kind)) == TokenKind_Eof) {
break;
}
String spelling = StringRangeAt(source, (int64_t)token.begin, (int64_t)token.end);
if (StringEqual(spelling, StringLiteral("/")) && token.end < (int64_t)(source).length && (uint8_t)source.data[token.end] == 47) {
break;
}
if ((StringEqual(spelling, StringLiteral("(")))) {
parens = (int32_t)((uint32_t)parens + 1u);
} else if ((StringEqual(spelling, StringLiteral(")")))) {
parens = (int32_t)((uint32_t)parens - 1u);
} else if (StringEqual(spelling, StringLiteral("["))) {
brackets = (int32_t)((uint32_t)brackets + 1u);
} else if (StringEqual(spelling, StringLiteral("]"))) {
brackets = (int32_t)((uint32_t)brackets - 1u);
} else if (StringEqual(spelling, StringLiteral("{"))) {
braces = (int32_t)((uint32_t)braces + 1u);
} else if (StringEqual(spelling, StringLiteral("}"))) {
braces = (int32_t)((uint32_t)braces - 1u);
} else if (parens == 0 && brackets == 0 && braces == 0 && !StringEqual(previous, StringLiteral(".")) && ((TokenKind)(token.kind)) == TokenKind_Ident) {
if (StringEqual(spelling, StringLiteral("ifx"))) {
break;
}
if (StringEqual(spelling, StringLiteral("then"))) {
if (token.begin == condition) {
ControlError* value_1 = &(result.error);
(*value_1) = ControlError_Condition;
return result;
}
String* value_2 = &(result.header);
String value_3 = StringRangeAt(source, (int64_t)0LL, (int64_t)token.begin);
String value_4 = StringView(NULL, 0);
{
String value_6 = value_3;
SourceRange value_7 = compiler_text_TrimRange(value_6);
value_4 = StringRangeAt(value_6, (int64_t)value_7.begin, (int64_t)value_7.end);
}
(*value_2) = value_4;
String value_8 = source;
int64_t value_9 = compiler_text_SkipSpace(source, token.end, true);
String body = StringRangeAt(value_8, (int64_t)value_9, (int64_t)value_8.length);
if ((int64_t)(body).length > 0LL && (uint8_t)body.data[0] == 123) {
String* value_10 = &(result.inline_body);
(*value_10) = body;
} else {
String* value_11 = &(result.queued_body);
(*value_11) = body;
}
return result;
}
}
previous = spelling;
at = token.end;
}
}
if (compiler_source_StartsWord(source, StringLiteral("else"))) {
String value_12 = source;
int64_t value_13 = compiler_text_SkipSpace(source, 4LL, true);
String body = StringRangeAt(value_12, (int64_t)value_13, (int64_t)value_12.length);
bool value_14 = (int64_t)(body).length > 0LL && (uint8_t)body.data[0] != 123;
bool value_15 = value_14;
if (value_15) {
bool value_16 = compiler_source_StartsWord(body, StringLiteral("if"));
value_15 = !value_16;
}
bool value_17 = value_15;
bool value_18 = value_17;
if (value_18) {
bool value_19 = compiler_source_StartsWord(body, StringLiteral("#if"));
value_18 = !value_19;
}
if (value_18) {
String* value_20 = &(result.header);
(*value_20) = StringRangeAt(source, (int64_t)0LL, (int64_t)4LL);
String* value_21 = &(result.queued_body);
(*value_21) = body;
}
}
return result;
}
CompileHeader
compiler_statement_CompileCondition(String source)
{
CompileHeader result = {0};
int64_t prefix = 0LL;
String value_0 = source;
String value_1 = StringLiteral("#if");
bool value_2 = false;
{
String value_4 = value_0;
String value_5 = value_1;
if ((int64_t)(value_4).length < (int64_t)(value_5).length || !StringEqual(StringRangeAt(value_4, (int64_t)0LL, (int64_t)(int64_t)(value_5).length), value_5)) {
value_2 = false;
goto value_3;
}
value_2 = (int64_t)(value_4).length == (int64_t)(value_5).length || compiler_text_SpaceByte((uint8_t)value_4.data[(int64_t)(value_5).length]);
value_3: ;
}
if (value_2) {
int32_t* value_6 = &(result.kind);
(*value_6) = 1;
prefix = 3LL;
} else {
String value_7 = source;
String value_8 = StringLiteral("else #if");
bool value_9 = false;
{
String value_11 = value_7;
String value_12 = value_8;
if ((int64_t)(value_11).length < (int64_t)(value_12).length || !StringEqual(StringRangeAt(value_11, (int64_t)0LL, (int64_t)(int64_t)(value_12).length), value_12)) {
value_9 = false;
goto value_10;
}
value_9 = (int64_t)(value_11).length == (int64_t)(value_12).length || compiler_text_SpaceByte((uint8_t)value_11.data[(int64_t)(value_12).length]);
value_10: ;
}
if (value_9) {
int32_t* value_13 = &(result.kind);
(*value_13) = 2;
prefix = 8LL;
} else {
String value_14 = source;
String value_15 = StringLiteral("} else #if");
bool value_16 = false;
{
String value_18 = value_14;
String value_19 = value_15;
if ((int64_t)(value_18).length < (int64_t)(value_19).length || !StringEqual(StringRangeAt(value_18, (int64_t)0LL, (int64_t)(int64_t)(value_19).length), value_19)) {
value_16 = false;
goto value_17;
}
value_16 = (int64_t)(value_18).length == (int64_t)(value_19).length || compiler_text_SpaceByte((uint8_t)value_18.data[(int64_t)(value_19).length]);
value_17: ;
}
if (value_16) {
int32_t* value_20 = &(result.kind);
(*value_20) = 2;
prefix = 10LL;
} else {
return result;
}
}
}
String value_21 = StringRangeAt(source, (int64_t)prefix, (int64_t)source.length);
String value_22 = StringView(NULL, 0);
{
String value_24 = value_21;
SourceRange value_25 = compiler_text_TrimRange(value_24);
value_22 = StringRangeAt(value_24, (int64_t)value_25.begin, (int64_t)value_25.end);
}
String condition = value_22;
if ((int64_t)(condition).length == 0LL || (uint8_t)condition.data[((int64_t)((uint64_t)((int64_t)(condition).length) - UINT64_C(1)))] != 123) {
return (CompileHeader){0};
}
String* value_26 = &(result.condition);
String value_27 = StringRangeAt(condition, (int64_t)0LL, (int64_t)((int64_t)((uint64_t)((int64_t)(condition).length) - UINT64_C(1))));
String value_28 = StringView(NULL, 0);
{
String value_30 = value_27;
SourceRange value_31 = compiler_text_TrimRange(value_30);
value_28 = StringRangeAt(value_30, (int64_t)value_31.begin, (int64_t)value_31.end);
}
(*value_26) = value_28;
if ((int64_t)(result.condition).length == 0LL) {
return (CompileHeader){0};
}
{
String value_32 = result.condition;
String loop_view_25 = StringRangeAt(value_32, (int64_t)0, (int64_t)value_32.length);
int64_t loop_count_25 = (int64_t)(loop_view_25).length;
int64_t loop_cursor_25 = 0LL;
while (loop_cursor_25 < loop_count_25) {
int64_t loop_index_25 = loop_cursor_25;
uint8_t byte = (uint8_t)loop_view_25.data[loop_index_25];
if (byte == 0) {
return (CompileHeader){0};
}
loop_cursor_25 = (int64_t)((uint64_t)loop_cursor_25 + UINT64_C(1));
}
}
return result;
}
bool
compiler_statement_CompileElse(String source)
{
return StringEqual(source, StringLiteral("} else {")) || StringEqual(source, StringLiteral("else {"));
}
bool
compiler_statement_StartsCompileCondition(String source)
{
String value_0 = source;
int64_t value_1 = compiler_text_SkipSpace(source, 0LL, true);
source = StringRangeAt(value_0, (int64_t)value_1, (int64_t)value_0.length);
bool value_2 = compiler_source_StartsWord(source, StringLiteral("#if"));
bool value_3 = value_2 || compiler_source_StartsWord(source, StringLiteral("else #if"));
return value_3 || compiler_source_StartsWord(source, StringLiteral("} else #if"));
}
LoopHeader
compiler_statement_ForHeader(String source, int64_t name_limit, int64_t text_limit)
{
LoopHeader result = {0};
String value_0 = source;
String value_1 = StringLiteral("for");
String value_2 = StringView(NULL, 0);
{
String value_4 = value_0;
String value_5 = value_1;
int64_t value_6 = text_limit;
String value_7 = StringView(NULL, 0);
{
String value_9 = value_4;
SourceRange value_10 = compiler_text_TrimRange(value_9);
value_7 = StringRangeAt(value_9, (int64_t)value_10.begin, (int64_t)value_10.end);
}
value_4 = value_7;
bool value_11 = compiler_source_StartsWord(value_4, value_5);
if (!value_11) {
value_2 = StringLiteral("");
goto value_3;
}
String value_12 = StringRangeAt(value_4, (int64_t)(int64_t)(value_5).length, (int64_t)value_4.length);
String value_13 = StringView(NULL, 0);
{
String value_15 = value_12;
SourceRange value_16 = compiler_text_TrimRange(value_15);
value_13 = StringRangeAt(value_15, (int64_t)value_16.begin, (int64_t)value_16.end);
}
String value_17 = value_13;
if ((int64_t)(value_17).length == 0LL || (int64_t)(value_17).length >= value_6 || (uint8_t)value_17.data[((int64_t)((uint64_t)((int64_t)(value_17).length) - UINT64_C(1)))] != 123) {
value_2 = StringLiteral("");
goto value_3;
}
String value_18 = StringRangeAt(value_17, (int64_t)0LL, (int64_t)((int64_t)((uint64_t)((int64_t)(value_17).length) - UINT64_C(1))));
String value_19 = StringView(NULL, 0);
{
String value_21 = value_18;
SourceRange value_22 = compiler_text_TrimRange(value_21);
value_19 = StringRangeAt(value_21, (int64_t)value_22.begin, (int64_t)value_22.end);
}
value_2 = value_19;
value_3: ;
}
String header = value_2;
if ((int64_t)(header).length == 0LL) {
return result;
}
while ((int64_t)(header).length > 0LL && ((uint8_t)header.data[0] == 60 || (uint8_t)header.data[0] == 42)) {
if ((uint8_t)header.data[0] == 60) {
if (result.reverse) {
return (LoopHeader){0};
}
bool* value_23 = &(result.reverse);
(*value_23) = true;
} else {
if (result.pointer) {
return (LoopHeader){0};
}
bool* value_24 = &(result.pointer);
(*value_24) = true;
}
String value_25 = StringRangeAt(header, (int64_t)1LL, (int64_t)header.length);
String value_26 = StringView(NULL, 0);
{
String value_28 = value_25;
SourceRange value_29 = compiler_text_TrimRange(value_28);
value_26 = StringRangeAt(value_28, (int64_t)value_29.begin, (int64_t)value_29.end);
}
header = value_26;
}
uint8_t delimiters[128] = {0};
int64_t depth = 0LL;
int64_t colon = -1LL;
int64_t dots = -1LL;
int64_t at = 0LL;
while (at < (int64_t)(header).length) {
uint8_t byte = (uint8_t)header.data[at];
if (byte == 0) {
return (LoopHeader){0};
}
if (byte == 34 || byte == 39) {
at = compiler_statement_AfterQuote(header, at);
if (at < 0LL) {
return (LoopHeader){0};
}
continue;
}
if (byte == 40 || byte == 91 || byte == 123) {
if (depth == 128) {
return (LoopHeader){0};
}
uint8_t* value_30 = &(delimiters[depth]);
(*value_30) = byte;
depth = (int64_t)((uint64_t)depth + UINT64_C(1));
} else if (byte == 41 || byte == 93 || byte == 125) {
if (depth == 0LL) {
return (LoopHeader){0};
}
uint8_t opening = (delimiters)[((int64_t)((uint64_t)depth - UINT64_C(1)))];
if ((byte == 41 && opening != 40) || (byte == 93 && opening != 91) || (byte == 125 && opening != 123)) {
return (LoopHeader){0};
}
depth = (int64_t)((uint64_t)depth - UINT64_C(1));
} else if (depth == 0LL) {
if (byte == 59) {
return (LoopHeader){.c_style = true};
}
if (byte == 58) {
if (colon >= 0LL || dots >= 0LL) {
return (LoopHeader){0};
}
colon = at;
}
if (byte == 46 && (int64_t)((uint64_t)at + UINT64_C(1)) < (int64_t)(header).length && (uint8_t)header.data[((int64_t)((uint64_t)at + UINT64_C(1)))] == 46) {
if (dots >= 0LL) {
return (LoopHeader){0};
}
dots = at;
at = (int64_t)((uint64_t)at + UINT64_C(1));
}
}
at = (int64_t)((uint64_t)at + UINT64_C(1));
}
if (depth != 0LL) {
return (LoopHeader){0};
}
String* value_31 = &(result.value_name);
(*value_31) = StringLiteral("it");
String* value_32 = &(result.index_name);
(*value_32) = StringLiteral("it_index");
String expression = header;
if (colon >= 0LL) {
String value_33 = StringRangeAt(header, (int64_t)0LL, (int64_t)colon);
String value_34 = StringView(NULL, 0);
{
String value_36 = value_33;
SourceRange value_37 = compiler_text_TrimRange(value_36);
value_34 = StringRangeAt(value_36, (int64_t)value_37.begin, (int64_t)value_37.end);
}
String names = value_34;
int64_t comma = compiler_statement_FindByte(names, 44);
if (comma >= 0LL) {
if (dots >= 0LL) {
return (LoopHeader){0};
}
String* value_38 = &(result.index_name);
String value_39 = StringRangeAt(names, (int64_t)((int64_t)((uint64_t)comma + UINT64_C(1))), (int64_t)names.length);
String value_40 = StringView(NULL, 0);
{
String value_42 = value_39;
SourceRange value_43 = compiler_text_TrimRange(value_42);
value_40 = StringRangeAt(value_42, (int64_t)value_43.begin, (int64_t)value_43.end);
}
(*value_38) = value_40;
String value_44 = StringRangeAt(names, (int64_t)0LL, (int64_t)comma);
String value_45 = StringView(NULL, 0);
{
String value_47 = value_44;
SourceRange value_48 = compiler_text_TrimRange(value_47);
value_45 = StringRangeAt(value_47, (int64_t)value_48.begin, (int64_t)value_48.end);
}
names = value_45;
}
String* value_49 = &(result.value_name);
(*value_49) = names;
String value_50 = StringRangeAt(header, (int64_t)((int64_t)((uint64_t)colon + UINT64_C(1))), (int64_t)header.length);
String value_51 = StringView(NULL, 0);
{
String value_53 = value_50;
SourceRange value_54 = compiler_text_TrimRange(value_53);
value_51 = StringRangeAt(value_53, (int64_t)value_54.begin, (int64_t)value_54.end);
}
expression = value_51;
}
String value_55 = result.value_name;
bool value_56 = false;
{
String value_58 = value_55;
int64_t value_59 = name_limit;
value_56 = (int64_t)(value_58).length < value_59 && compiler_source_IdentifierText(value_58, false);
}
if (!value_56) {
return (LoopHeader){0};
}
if (dots >= 0LL) {
if (result.pointer) {
return (LoopHeader){0};
}
String* value_60 = &(result.first);
String value_61 = StringRangeAt(header, (int64_t)((int64_t)((uint64_t)colon + UINT64_C(1))), (int64_t)dots);
String value_62 = StringView(NULL, 0);
{
String value_64 = value_61;
SourceRange value_65 = compiler_text_TrimRange(value_64);
value_62 = StringRangeAt(value_64, (int64_t)value_65.begin, (int64_t)value_65.end);
}
(*value_60) = value_62;
String* value_66 = &(result.last);
String value_67 = StringRangeAt(header, (int64_t)((int64_t)((uint64_t)dots + UINT64_C(2))), (int64_t)header.length);
String value_68 = StringView(NULL, 0);
{
String value_70 = value_67;
SourceRange value_71 = compiler_text_TrimRange(value_70);
value_68 = StringRangeAt(value_70, (int64_t)value_71.begin, (int64_t)value_71.end);
}
(*value_66) = value_68;
if ((int64_t)(result.first).length == 0LL || (int64_t)(result.last).length == 0LL) {
return (LoopHeader){0};
}
LoopKind* value_72 = &(result.kind);
(*value_72) = LoopKind_Range;
} else {
bool value_73 = (int64_t)(expression).length == 0LL;
if (!value_73) {
String value_74 = result.index_name;
bool value_75 = false;
{
String value_77 = value_74;
int64_t value_78 = name_limit;
value_75 = (int64_t)(value_77).length < value_78 && compiler_source_IdentifierText(value_77, false);
}
value_73 = !value_75;
}
if (value_73 || StringEqual(result.value_name, result.index_name)) {
return (LoopHeader){0};
}
String* value_79 = &(result.collection);
(*value_79) = expression;
LoopKind* value_80 = &(result.kind);
(*value_80) = LoopKind_Collection;
}
return result;
}
NamedWhile
compiler_statement_WhileHeader(String source, int64_t name_limit, int64_t text_limit)
{
NamedWhile result = {0};
String value_0 = source;
String value_1 = StringLiteral("while");
String value_2 = StringView(NULL, 0);
{
String value_4 = value_0;
String value_5 = value_1;
int64_t value_6 = text_limit;
String value_7 = StringView(NULL, 0);
{
String value_9 = value_4;
SourceRange value_10 = compiler_text_TrimRange(value_9);
value_7 = StringRangeAt(value_9, (int64_t)value_10.begin, (int64_t)value_10.end);
}
value_4 = value_7;
bool value_11 = compiler_source_StartsWord(value_4, value_5);
if (!value_11) {
value_2 = StringLiteral("");
goto value_3;
}
String value_12 = StringRangeAt(value_4, (int64_t)(int64_t)(value_5).length, (int64_t)value_4.length);
String value_13 = StringView(NULL, 0);
{
String value_15 = value_12;
SourceRange value_16 = compiler_text_TrimRange(value_15);
value_13 = StringRangeAt(value_15, (int64_t)value_16.begin, (int64_t)value_16.end);
}
String value_17 = value_13;
if ((int64_t)(value_17).length == 0LL || (int64_t)(value_17).length >= value_6 || (uint8_t)value_17.data[((int64_t)((uint64_t)((int64_t)(value_17).length) - UINT64_C(1)))] != 123) {
value_2 = StringLiteral("");
goto value_3;
}
String value_18 = StringRangeAt(value_17, (int64_t)0LL, (int64_t)((int64_t)((uint64_t)((int64_t)(value_17).length) - UINT64_C(1))));
String value_19 = StringView(NULL, 0);
{
String value_21 = value_18;
SourceRange value_22 = compiler_text_TrimRange(value_21);
value_19 = StringRangeAt(value_21, (int64_t)value_22.begin, (int64_t)value_22.end);
}
value_2 = value_19;
value_3: ;
}
String header = value_2;
int64_t at = 0LL;
while (at < (int64_t)(header).length && compiler_text_IdentifierByte((uint8_t)header.data[at])) {
at = (int64_t)((uint64_t)at + UINT64_C(1));
}
String name = StringRangeAt(header, (int64_t)0LL, (int64_t)at);
String value_23 = StringRangeAt(header, (int64_t)at, (int64_t)header.length);
String value_24 = StringView(NULL, 0);
{
String value_26 = value_23;
SourceRange value_27 = compiler_text_TrimRange(value_26);
value_24 = StringRangeAt(value_26, (int64_t)value_27.begin, (int64_t)value_27.end);
}
String after = value_24;
bool value_28 = false;
{
String value_30 = name;
int64_t value_31 = name_limit;
value_28 = (int64_t)(value_30).length < value_31 && compiler_source_IdentifierText(value_30, false);
}
if (!value_28 || (int64_t)(after).length < 2LL || !StringEqual(StringRangeAt(after, (int64_t)0LL, (int64_t)2LL), StringLiteral(":="))) {
return result;
}
String value_32 = StringRangeAt(after, (int64_t)2LL, (int64_t)after.length);
String value_33 = StringView(NULL, 0);
{
String value_35 = value_32;
SourceRange value_36 = compiler_text_TrimRange(value_35);
value_33 = StringRangeAt(value_35, (int64_t)value_36.begin, (int64_t)value_36.end);
}
String condition = value_33;
if ((int64_t)(condition).length == 0LL) {
return result;
}
return (NamedWhile){.valid = true, .name = name, .condition = condition};
}
LoopControl
compiler_statement_ControlTarget(String source, bool continuation, int64_t name_limit)
{
LoopControl result = {0};
String value_0 = source;
String value_1 = StringView(NULL, 0);
{
String value_3 = value_0;
SourceRange value_4 = compiler_text_TrimRange(value_3);
value_1 = StringRangeAt(value_3, (int64_t)value_4.begin, (int64_t)value_4.end);
}
source = value_1;
String keyword = StringLiteral("break");
if (continuation) {
keyword = StringLiteral("continue");
}
bool value_5 = (int64_t)(source).length == (int64_t)((uint64_t)((int64_t)(keyword).length) + UINT64_C(1)) && StringEqual(StringRangeAt(source, (int64_t)0LL, (int64_t)(int64_t)(keyword).length), keyword);
bool bare_semicolon = value_5 && (uint8_t)source.data[(int64_t)(keyword).length] == 59;
bool value_6 = compiler_source_StartsWord(source, keyword);
if (!value_6 && !bare_semicolon) {
return result;
}
String value_7 = StringRangeAt(source, (int64_t)(int64_t)(keyword).length, (int64_t)source.length);
String value_8 = StringView(NULL, 0);
{
String value_10 = value_7;
SourceRange value_11 = compiler_text_TrimRange(value_10);
value_8 = StringRangeAt(value_10, (int64_t)value_11.begin, (int64_t)value_11.end);
}
String target = value_8;
if ((int64_t)(target).length > 0LL && (uint8_t)target.data[((int64_t)((uint64_t)((int64_t)(target).length) - UINT64_C(1)))] == 59) {
String value_12 = StringRangeAt(target, (int64_t)0LL, (int64_t)((int64_t)((uint64_t)((int64_t)(target).length) - UINT64_C(1))));
String value_13 = StringView(NULL, 0);
{
String value_15 = value_12;
SourceRange value_16 = compiler_text_TrimRange(value_15);
value_13 = StringRangeAt(value_15, (int64_t)value_16.begin, (int64_t)value_16.end);
}
target = value_13;
}
bool value_17 = (int64_t)(target).length > 0LL;
if (value_17) {
bool value_18 = false;
{
String value_20 = target;
int64_t value_21 = name_limit;
value_18 = (int64_t)(value_20).length < value_21 && compiler_source_IdentifierText(value_20, false);
}
value_17 = !value_18;
}
if (value_17) {
return result;
}
return (LoopControl){.valid = true, .name = target};
}
bool
compiler_statement_Mentions(String source, String name)
{
int64_t at = 0LL;
while (at < (int64_t)(source).length) {
Scan token = compiler_scan_NextToken(source, at, 1, 1);
if (((TokenKind)(token.kind)) == TokenKind_Eof) {
break;
}
if (((TokenKind)(token.kind)) == TokenKind_Ident && StringEqual(StringRangeAt(source, (int64_t)token.begin, (int64_t)token.end), name)) {
return true;
}
at = token.end;
}
return false;
}
bool
compiler_statement_Changes(String source, String name, bool assignment)
{
int64_t at = 0LL;
bool first = true;
bool address = false;
bool operand = false;
while (at < (int64_t)(source).length) {
Scan token = compiler_scan_NextToken(source, at, 1, 1);
if (((TokenKind)(token.kind)) == TokenKind_Eof) {
break;
}
String spelling = StringRangeAt(source, (int64_t)token.begin, (int64_t)token.end);
if (((TokenKind)(token.kind)) == TokenKind_Ident && StringEqual(spelling, name) && (address || (first && assignment))) {
return true;
}
address = StringEqual(spelling, StringLiteral("*")) && !operand;
bool value_0 = ((TokenKind)(token.kind)) == TokenKind_Ident || ((TokenKind)(token.kind)) == TokenKind_Int || ((TokenKind)(token.kind)) == TokenKind_Float;
bool value_1 = value_0 || ((TokenKind)(token.kind)) == TokenKind_String || ((TokenKind)(token.kind)) == TokenKind_Char;
operand = ((value_1 || (StringEqual(spelling, StringLiteral(")")))) || StringEqual(spelling, StringLiteral("]")));
first = false;
at = token.end;
}
return false;
}
bool
compiler_statement_PlainName(String source)
{
Scan token = compiler_scan_NextToken(source, 0LL, 1, 1);
bool value_0 = ((TokenKind)(token.kind)) == TokenKind_Ident;
if (value_0) {
Scan value_1 = compiler_scan_NextToken(source, token.end, 1, 1);
value_0 = (((TokenKind)(value_1.kind)) == TokenKind_Eof);
}
return value_0;
}
static bool
compiler_statement_CompilePrefix(String source, String prefix)
{
if ((int64_t)(source).length < (int64_t)(prefix).length || !StringEqual(StringRangeAt(source, (int64_t)0LL, (int64_t)(int64_t)(prefix).length), prefix)) {
return false;
}
return (int64_t)(source).length == (int64_t)(prefix).length || compiler_text_SpaceByte((uint8_t)source.data[(int64_t)(prefix).length]);
}
static String
compiler_statement_Trim(String source)
{
SourceRange range = compiler_text_TrimRange(source);
return StringRangeAt(source, (int64_t)range.begin, (int64_t)range.end);
}
static bool
compiler_statement_Name(String source, int64_t limit)
{
return (int64_t)(source).length < limit && compiler_source_IdentifierText(source, false);
}
static String
compiler_statement_HeaderBody(String source, String keyword, int64_t limit)
{
String value_0 = source;
String value_1 = StringView(NULL, 0);
{
String value_3 = value_0;
SourceRange value_4 = compiler_text_TrimRange(value_3);
value_1 = StringRangeAt(value_3, (int64_t)value_4.begin, (int64_t)value_4.end);
}
source = value_1;
bool value_5 = compiler_source_StartsWord(source, keyword);
if (!value_5) {
return StringLiteral("");
}
String value_6 = StringRangeAt(source, (int64_t)(int64_t)(keyword).length, (int64_t)source.length);
String value_7 = StringView(NULL, 0);
{
String value_9 = value_6;
SourceRange value_10 = compiler_text_TrimRange(value_9);
value_7 = StringRangeAt(value_9, (int64_t)value_10.begin, (int64_t)value_10.end);
}
String header = value_7;
if ((int64_t)(header).length == 0LL || (int64_t)(header).length >= limit || (uint8_t)header.data[((int64_t)((uint64_t)((int64_t)(header).length) - UINT64_C(1)))] != 123) {
return StringLiteral("");
}
String value_11 = StringRangeAt(header, (int64_t)0LL, (int64_t)((int64_t)((uint64_t)((int64_t)(header).length) - UINT64_C(1))));
String value_12 = StringView(NULL, 0);
{
String value_14 = value_11;
SourceRange value_15 = compiler_text_TrimRange(value_14);
value_12 = StringRangeAt(value_14, (int64_t)value_15.begin, (int64_t)value_15.end);
}
return value_12;
}
static int64_t
compiler_statement_AfterQuote(String source, int64_t start)
{
uint8_t quote = (uint8_t)source.data[start];
int64_t at = (int64_t)((uint64_t)start + UINT64_C(1));
while (at < (int64_t)(source).length) {
uint8_t byte = (uint8_t)source.data[at];
if (byte == 0) {
return -1LL;
}
at = (int64_t)((uint64_t)at + UINT64_C(1));
if (byte == quote) {
return at;
}
if (byte == 92) {
if (at == (int64_t)(source).length || (uint8_t)source.data[at] == 0) {
return -1LL;
}
at = (int64_t)((uint64_t)at + UINT64_C(1));
}
}
return -1LL;
}
static int64_t
compiler_statement_FindByte(String source, uint8_t wanted)
{
{
int64_t range_first_0 = 0LL;
int64_t range_last_0 = (int64_t)((uint64_t)((int64_t)(source).length) - UINT64_C(1));
int64_t at = range_first_0;
if (at <= range_last_0) for (;;) {
if ((uint8_t)source.data[at] == wanted) {
return at;
}
if (at == range_last_0) {
break;
}
at = (int64_t)((uint64_t)at + UINT64_C(1));
}
}
return -1LL;
}