4052 lines
170 KiB
C
4052 lines
170 KiB
C
/* Generated by zi2c from declaration.zi. */
|
|
#define ZIRAN_DECLARATION_H_SOURCE 1
|
|
#include <stdbool.h>
|
|
#include "zir_string.h"
|
|
#define ZIRAN_DECLARATION_H_PRIVATE 1
|
|
#include "declaration.h"
|
|
#undef ZIRAN_DECLARATION_H_PRIVATE
|
|
#ifndef ZIRAN_HELPER_ZiShl64
|
|
#define ZIRAN_HELPER_ZiShl64
|
|
#if (defined(__GNUC__) || defined(__clang__)) && !defined(__OPTIMIZE__)
|
|
#define ZiShl64(a, s, w) __extension__ ({ uint64_t __zi_a = (a); uint64_t __zi_s = (s); if(__zi_s >= (uint64_t)(w)) abort(); (uint64_t)(__zi_a << __zi_s); })
|
|
#else
|
|
static inline uint64_t ZiShl64(uint64_t a, uint64_t s, int w) {
|
|
if(s >= (uint64_t)w) abort();
|
|
return (uint64_t)(a << s);
|
|
}
|
|
#endif
|
|
#endif
|
|
#include "ziran_compiler.h"
|
|
static int64_t declaration_Find(String source, String needle) ZIRAN_MAYBE_UNUSED;
|
|
static String declaration_Trim(String source) ZIRAN_MAYBE_UNUSED;
|
|
static void declaration_Put(Slice output, int64_t* used, String source) ZIRAN_MAYBE_UNUSED;
|
|
static uint8_t declaration_Byte(String source, int64_t at) ZIRAN_MAYBE_UNUSED;
|
|
static int64_t declaration_AfterQuoted(String source, int64_t at) ZIRAN_MAYBE_UNUSED;
|
|
static int64_t declaration_Digits(String source, int64_t at) ZIRAN_MAYBE_UNUSED;
|
|
static bool declaration_FloatLiteral(String source) ZIRAN_MAYBE_UNUSED;
|
|
static int64_t declaration_IntegerBits(String name) ZIRAN_MAYBE_UNUSED;
|
|
static QuotedText declaration_Quoted(String source, int64_t limit) ZIRAN_MAYBE_UNUSED;
|
|
static String declaration_SymbolBeforeColons(String source, int64_t limit) ZIRAN_MAYBE_UNUSED;
|
|
static String declaration_Basename(String source) ZIRAN_MAYBE_UNUSED;
|
|
static QuotedText declaration_UsingQuoted(String source, int64_t limit) ZIRAN_MAYBE_UNUSED;
|
|
static bool declaration_ParameterIn(String source, String parameter) ZIRAN_MAYBE_UNUSED;
|
|
static String declaration_StatementValue(String source) ZIRAN_MAYBE_UNUSED;
|
|
static void declaration_PutByte(Slice output, int64_t* used, uint8_t byte) ZIRAN_MAYBE_UNUSED;
|
|
static int64_t declaration_AfterComment(String source, int64_t at) ZIRAN_MAYBE_UNUSED;
|
|
static bool declaration_IsAsciiLetter(uint8_t byte) ZIRAN_MAYBE_UNUSED;
|
|
static bool declaration_IsPrintfFlag(uint8_t byte) ZIRAN_MAYBE_UNUSED;
|
|
static bool declaration_IsPrintfConversion(uint8_t byte) ZIRAN_MAYBE_UNUSED;
|
|
static void declaration_AddScanPiece(BuilderPrintScan* result, BuilderPrintPiece piece) ZIRAN_MAYBE_UNUSED;
|
|
static void declaration_AddPrintPiece(PrintRewrite* result, Slice output, int32_t maximum, String builder, String value, bool literal) ZIRAN_MAYBE_UNUSED;
|
|
|
|
static int64_t
|
|
declaration_Find(String source, String needle)
|
|
{
|
|
{
|
|
int64_t range_first_0 = 0LL;
|
|
int64_t range_last_0 = (int64_t)(source).length;
|
|
int64_t at = range_first_0;
|
|
if (at <= range_last_0) for (;;) {
|
|
if ((int64_t)(needle).length <= (int64_t)((uint64_t)((int64_t)(source).length) - (uint64_t)at) && StringEqual(StringRangeAt(source, (int64_t)at, (int64_t)((int64_t)((uint64_t)at + (uint64_t)((int64_t)(needle).length)))), needle)) {
|
|
return at;
|
|
}
|
|
if (at == range_last_0) {
|
|
break;
|
|
}
|
|
at = (int64_t)((uint64_t)at + UINT64_C(1));
|
|
}
|
|
}
|
|
return -1LL;
|
|
}
|
|
|
|
static String
|
|
declaration_Trim(String source)
|
|
{
|
|
SourceRange range = source_text_TrimRange(source);
|
|
return StringRangeAt(source, (int64_t)range.begin, (int64_t)range.end);
|
|
}
|
|
|
|
static void
|
|
declaration_Put(Slice output, int64_t* used, String source)
|
|
{
|
|
for (int64_t it_index = 0LL; it_index < (int64_t)(source).length; it_index++) {
|
|
uint8_t byte = (uint8_t)source.data[it_index];
|
|
int64_t value_0 = *(used);
|
|
int64_t value_1 = (int64_t)(output).length;
|
|
if (value_0 < value_1) {
|
|
uint8_t* value_2 = &(((uint8_t *)(output).data)[*(used)]);
|
|
(*value_2) = byte;
|
|
}
|
|
int64_t* value_3 = &((*(used)));
|
|
(*value_3) = (int64_t)((uint64_t)((*value_3)) + UINT64_C(1));
|
|
}
|
|
}
|
|
|
|
static uint8_t
|
|
declaration_Byte(String source, int64_t at)
|
|
{
|
|
if (at < 0LL || at >= (int64_t)(source).length) {
|
|
return 0;
|
|
}
|
|
return (uint8_t)source.data[at];
|
|
}
|
|
|
|
static int64_t
|
|
declaration_AfterQuoted(String source, int64_t at)
|
|
{
|
|
uint8_t quote = (uint8_t)source.data[at];
|
|
at = (int64_t)((uint64_t)at + UINT64_C(1));
|
|
while (at < (int64_t)(source).length) {
|
|
uint8_t byte = (uint8_t)source.data[at];
|
|
at = (int64_t)((uint64_t)at + UINT64_C(1));
|
|
if (byte == quote) {
|
|
return at;
|
|
}
|
|
if (byte == 92 && at < (int64_t)(source).length) {
|
|
at = (int64_t)((uint64_t)at + UINT64_C(1));
|
|
}
|
|
}
|
|
return (int64_t)((uint64_t)((int64_t)(source).length) + UINT64_C(1));
|
|
}
|
|
|
|
static int64_t
|
|
declaration_Digits(String source, int64_t at)
|
|
{
|
|
while (at < (int64_t)(source).length && (uint8_t)source.data[at] >= 48 && (uint8_t)source.data[at] <= 57) {
|
|
at = (int64_t)((uint64_t)at + UINT64_C(1));
|
|
}
|
|
return at;
|
|
}
|
|
|
|
static bool
|
|
declaration_FloatLiteral(String source)
|
|
{
|
|
int64_t whole = declaration_Digits(source, 0LL);
|
|
bool value_0 = whole == 0LL;
|
|
if (!value_0) {
|
|
String value_1 = source;
|
|
uint8_t value_2 = 0;
|
|
{
|
|
String value_4 = value_1;
|
|
int64_t value_5 = whole;
|
|
if (value_5 < 0LL || value_5 >= (int64_t)(value_4).length) {
|
|
value_2 = 0;
|
|
goto value_3;
|
|
}
|
|
value_2 = (uint8_t)value_4.data[value_5];
|
|
value_3: ;
|
|
}
|
|
value_0 = (value_2 != 46);
|
|
}
|
|
if (value_0) {
|
|
return false;
|
|
}
|
|
int64_t fraction = declaration_Digits(source, (int64_t)((uint64_t)whole + UINT64_C(1)));
|
|
if (fraction == (int64_t)((uint64_t)whole + UINT64_C(1))) {
|
|
return false;
|
|
}
|
|
if (fraction == (int64_t)(source).length) {
|
|
return true;
|
|
}
|
|
if ((uint8_t)source.data[fraction] != 101 && (uint8_t)source.data[fraction] != 69) {
|
|
return false;
|
|
}
|
|
int64_t at = (int64_t)((uint64_t)fraction + UINT64_C(1));
|
|
String value_6 = source;
|
|
int64_t value_7 = at;
|
|
uint8_t value_8 = 0;
|
|
{
|
|
String value_10 = value_6;
|
|
int64_t value_11 = value_7;
|
|
if (value_11 < 0LL || value_11 >= (int64_t)(value_10).length) {
|
|
value_8 = 0;
|
|
goto value_9;
|
|
}
|
|
value_8 = (uint8_t)value_10.data[value_11];
|
|
value_9: ;
|
|
}
|
|
bool value_12 = value_8 == 43;
|
|
if (!value_12) {
|
|
String value_13 = source;
|
|
int64_t value_14 = at;
|
|
uint8_t value_15 = 0;
|
|
{
|
|
String value_17 = value_13;
|
|
int64_t value_18 = value_14;
|
|
if (value_18 < 0LL || value_18 >= (int64_t)(value_17).length) {
|
|
value_15 = 0;
|
|
goto value_16;
|
|
}
|
|
value_15 = (uint8_t)value_17.data[value_18];
|
|
value_16: ;
|
|
}
|
|
value_12 = (value_15 == 45);
|
|
}
|
|
if (value_12) {
|
|
at = (int64_t)((uint64_t)at + UINT64_C(1));
|
|
}
|
|
int64_t exponent = declaration_Digits(source, at);
|
|
return exponent > at && exponent == (int64_t)(source).length;
|
|
}
|
|
|
|
static int64_t
|
|
declaration_IntegerBits(String name)
|
|
{
|
|
String widths[8] = {StringLiteral("s8"), StringLiteral("u8"), StringLiteral("s16"), StringLiteral("u16"), StringLiteral("s32"), StringLiteral("u32"), StringLiteral("s64"), StringLiteral("u64")};
|
|
int64_t bits[8] = {8LL, 8LL, 16LL, 16LL, 32LL, 32LL, 64LL, 64LL};
|
|
{
|
|
int64_t range_first_2 = 0LL;
|
|
int64_t range_last_2 = 7LL;
|
|
int64_t index = range_first_2;
|
|
if (index <= range_last_2) for (;;) {
|
|
if (StringEqual(name, (widths)[index])) {
|
|
return (bits)[index];
|
|
}
|
|
if (index == range_last_2) {
|
|
break;
|
|
}
|
|
index = (int64_t)((uint64_t)index + UINT64_C(1));
|
|
}
|
|
}
|
|
return 0LL;
|
|
}
|
|
|
|
static QuotedText
|
|
declaration_Quoted(String source, int64_t limit)
|
|
{
|
|
int64_t begin = declaration_Find(source, StringLiteral("\""));
|
|
if (begin < 0LL) {
|
|
return (QuotedText){0};
|
|
}
|
|
int64_t end = declaration_Find(StringRangeAt(source, (int64_t)((int64_t)((uint64_t)begin + UINT64_C(1))), (int64_t)source.length), StringLiteral("\""));
|
|
if (end < 0LL || end >= limit) {
|
|
return (QuotedText){0};
|
|
}
|
|
end = (int64_t)((uint64_t)end + ((uint64_t)begin + UINT64_C(1)));
|
|
return (QuotedText){.valid = true, .value = StringRangeAt(source, (int64_t)((int64_t)((uint64_t)begin + UINT64_C(1))), (int64_t)end), .end = (int64_t)((uint64_t)end + UINT64_C(1))};
|
|
}
|
|
|
|
static String
|
|
declaration_SymbolBeforeColons(String source, int64_t limit)
|
|
{
|
|
int64_t colons = declaration_Find(source, StringLiteral("::"));
|
|
if (colons < 0LL) {
|
|
return StringLiteral("");
|
|
}
|
|
int64_t begin = source_text_SkipSpace(source, 0LL, true);
|
|
int64_t end = begin;
|
|
while (end < colons && source_text_IdentifierByte((uint8_t)source.data[end])) {
|
|
end = (int64_t)((uint64_t)end + UINT64_C(1));
|
|
}
|
|
bool value_0 = end == begin || (int64_t)((uint64_t)end - (uint64_t)begin) >= limit;
|
|
if (!value_0) {
|
|
int64_t value_1 = source_text_SkipSpace(source, end, true);
|
|
value_0 = (value_1 != colons);
|
|
}
|
|
if (value_0) {
|
|
return StringLiteral("");
|
|
}
|
|
return StringRangeAt(source, (int64_t)begin, (int64_t)end);
|
|
}
|
|
|
|
static String
|
|
declaration_Basename(String source)
|
|
{
|
|
int64_t begin = 0LL;
|
|
{
|
|
int64_t range_first_1 = 0LL;
|
|
int64_t range_last_1 = (int64_t)((uint64_t)((int64_t)(source).length) - UINT64_C(1));
|
|
int64_t at = range_first_1;
|
|
if (at <= range_last_1) for (;;) {
|
|
if ((uint8_t)source.data[at] == 47) {
|
|
begin = (int64_t)((uint64_t)at + UINT64_C(1));
|
|
}
|
|
if (at == range_last_1) {
|
|
break;
|
|
}
|
|
at = (int64_t)((uint64_t)at + UINT64_C(1));
|
|
}
|
|
}
|
|
return StringRangeAt(source, (int64_t)begin, (int64_t)source.length);
|
|
}
|
|
|
|
String
|
|
declaration_ErrorText(DeclarationError error)
|
|
{
|
|
if (error == DeclarationError_ExportQuote) {
|
|
return StringLiteral("#program_export requires a valid quoted symbol");
|
|
}
|
|
if (error == DeclarationError_ExportName) {
|
|
return StringLiteral("#program_export symbol must be an identifier");
|
|
}
|
|
if (error == DeclarationError_Parameters) {
|
|
return StringLiteral("too many procedure parameters");
|
|
}
|
|
if (error == DeclarationError_DefaultValue) {
|
|
return StringLiteral("default parameter needs a value");
|
|
}
|
|
if (error == DeclarationError_ProcedureTypeCount) {
|
|
return StringLiteral("invalid procedure type parameters");
|
|
}
|
|
if (error == DeclarationError_ProcedureTypeName) {
|
|
return StringLiteral("procedure type parameter needs a name");
|
|
}
|
|
if (error == DeclarationError_ProcedureTypeType) {
|
|
return StringLiteral("procedure type parameter needs a type");
|
|
}
|
|
if (error == DeclarationError_ProcedureTypeDefault) {
|
|
return StringLiteral("defaults on procedure type parameters are not supported");
|
|
}
|
|
if (error == DeclarationError_UsingModifier) {
|
|
return StringLiteral("using parameter modifiers are not supported");
|
|
}
|
|
if (error == DeclarationError_UsingType) {
|
|
return StringLiteral("using parameter needs name: Type");
|
|
}
|
|
if (error == DeclarationError_UsingName) {
|
|
return StringLiteral("using parameter needs a plain name");
|
|
}
|
|
if (error == DeclarationError_ImportQuote) {
|
|
return StringLiteral("Jai #import requires a quoted module or file name");
|
|
}
|
|
if (error == DeclarationError_ImportCharacter) {
|
|
return StringLiteral("#import target contains a character that cannot appear in an include path");
|
|
}
|
|
if (error == DeclarationError_ImportMode) {
|
|
return StringLiteral("unsupported #import mode");
|
|
}
|
|
if (error == DeclarationError_ImportDirSyntax) {
|
|
return StringLiteral("#import, dir requires a quoted path and ';'");
|
|
}
|
|
if (error == DeclarationError_ImportDirPath) {
|
|
return StringLiteral("#import, dir requires a relative directory path");
|
|
}
|
|
if (error == DeclarationError_ImportDirName) {
|
|
return StringLiteral("#import, dir path needs an identifier directory name");
|
|
}
|
|
if (error == DeclarationError_ImportFileSyntax) {
|
|
return StringLiteral("#import, file requires a quoted path and ';'");
|
|
}
|
|
if (error == DeclarationError_ImportFilePath) {
|
|
return StringLiteral("#import, file requires a relative .zi, .zir, .ts, .tsx, .mts, or .cts path");
|
|
}
|
|
if (error == DeclarationError_ImportFileName) {
|
|
return StringLiteral("#import, file path needs an identifier filename");
|
|
}
|
|
if (error == DeclarationError_ImportAlias) {
|
|
return StringLiteral("import alias must start with a letter or underscore");
|
|
}
|
|
if (error == DeclarationError_ImportAliasLimit) {
|
|
return StringLiteral("import name exceeds the 127-byte limit; give it an explicit alias");
|
|
}
|
|
if (error == DeclarationError_ImportTarget) {
|
|
return StringLiteral("Jai #import requires a module identifier or PACKAGE/export/path with identifier segments; use #import, file for paths");
|
|
}
|
|
if (error == DeclarationError_ImportPackage) {
|
|
return StringLiteral("a package import uses identifier path segments, as in #import \"PACKAGE/export/path\"");
|
|
}
|
|
if (error == DeclarationError_ImportUsing) {
|
|
return StringLiteral("using #import requires a named module alias");
|
|
}
|
|
if (error == DeclarationError_ImportParameterList) {
|
|
return StringLiteral("an import's module parameters are a list (NAME = value, ...) before the closing ';'");
|
|
}
|
|
if (error == DeclarationError_ImportParameterMode) {
|
|
return StringLiteral("module parameters need a quoted module import; #import, file and #import, dir take none");
|
|
}
|
|
if (error == DeclarationError_ParameterListSyntax) {
|
|
return StringLiteral("#module_parameters needs a parenthesized list, as in #module_parameters(NAME := value);");
|
|
}
|
|
if (error == DeclarationError_ParameterName) {
|
|
return StringLiteral("a module parameter name must be an identifier");
|
|
}
|
|
if (error == DeclarationError_ParameterValue) {
|
|
return StringLiteral("a module parameter value must be a literal: an integer, a float, a string, true or false");
|
|
}
|
|
if (error == DeclarationError_ParameterDuplicate) {
|
|
return StringLiteral("a module parameter list names the same parameter twice");
|
|
}
|
|
if (error == DeclarationError_ParameterType) {
|
|
return StringLiteral("a module parameter type must be bool, string, an integer type or a float type");
|
|
}
|
|
if (error == DeclarationError_ParameterDefault) {
|
|
return StringLiteral("a module parameter needs a default value: NAME := value or NAME: Type = value");
|
|
}
|
|
if (error == DeclarationError_ParameterFit) {
|
|
return StringLiteral("a module parameter's default value does not fit its declared type");
|
|
}
|
|
if (error == DeclarationError_InsertSyntax) {
|
|
return StringLiteral("#insert needs NAME; naming a compile-time string constant");
|
|
}
|
|
if (error == DeclarationError_LibraryQuote) {
|
|
return StringLiteral("#system_library requires a quoted library name");
|
|
}
|
|
if (error == DeclarationError_LibraryEnd) {
|
|
return StringLiteral("#system_library declaration must end with ';'");
|
|
}
|
|
if (error == DeclarationError_LibraryCharacter) {
|
|
return StringLiteral("#system_library name contains an invalid character");
|
|
}
|
|
if (error == DeclarationError_UsingKind) {
|
|
return StringLiteral("using modifier must be only, except, or map");
|
|
}
|
|
if (error == DeclarationError_UsingList) {
|
|
return StringLiteral("using modifier requires a parenthesized name list");
|
|
}
|
|
if (error == DeclarationError_UsingEntry) {
|
|
return StringLiteral("using modifier entries must be quoted names");
|
|
}
|
|
if (error == DeclarationError_UsingMap) {
|
|
return StringLiteral("using map entries need \"new\" = \"old\"");
|
|
}
|
|
if (error == DeclarationError_ForeignResults) {
|
|
return StringLiteral("#go_results requires one foreign procedure result record");
|
|
}
|
|
if (error == DeclarationError_ForeignField) {
|
|
return StringLiteral("#go_field requires one foreign field accessor without #go_results");
|
|
}
|
|
if (error == DeclarationError_ForeignDefer) {
|
|
return StringLiteral("#go_defer requires one foreign procedure without result or field attributes");
|
|
}
|
|
if (error == DeclarationError_ForeignVariadic) {
|
|
return StringLiteral("#go_variadic requires one foreign procedure with a final slice parameter");
|
|
}
|
|
if (error == DeclarationError_ForeignReads) {
|
|
return StringLiteral("#reads goes once before #foreign on a foreign procedure");
|
|
}
|
|
if (error == DeclarationError_ForeignType) {
|
|
return StringLiteral("foreign type requires Name :: #type #foreign library;");
|
|
}
|
|
if (error == DeclarationError_ForeignBody) {
|
|
return StringLiteral("#foreign procedure declarations cannot have a body");
|
|
}
|
|
if (error == DeclarationError_ForeignLibrary) {
|
|
return StringLiteral("#foreign requires a named #system_library");
|
|
}
|
|
if (error == DeclarationError_ForeignSymbol) {
|
|
return StringLiteral("#foreign alternate symbol must be an identifier or a Go method expression");
|
|
}
|
|
if (error == DeclarationError_ForeignEnd) {
|
|
return StringLiteral("#foreign declaration must end with ';'");
|
|
}
|
|
if (error == DeclarationError_ForeignHostRename) {
|
|
return StringLiteral("host capability cannot rename a #foreign symbol");
|
|
}
|
|
if (error == DeclarationError_ForeignGoResults) {
|
|
return StringLiteral("#go_results requires an explicit Go foreign target");
|
|
}
|
|
if (error == DeclarationError_ForeignGoField) {
|
|
return StringLiteral("#go_field requires an explicit Go foreign target");
|
|
}
|
|
if (error == DeclarationError_ForeignGoDefer) {
|
|
return StringLiteral("#go_defer requires an explicit Go foreign target");
|
|
}
|
|
if (error == DeclarationError_ForeignGoVariadic) {
|
|
return StringLiteral("#go_variadic requires an explicit Go foreign target");
|
|
}
|
|
if (error == DeclarationError_ForeignDataType) {
|
|
return StringLiteral("foreign data requires Name: Type #foreign library;");
|
|
}
|
|
if (error == DeclarationError_ForeignDataValue) {
|
|
return StringLiteral("foreign data is read-only and cannot have an initializer or attributes");
|
|
}
|
|
if (error == DeclarationError_ResultCount) {
|
|
return StringLiteral("a procedure can have at most 16 results");
|
|
}
|
|
if (error == DeclarationError_ResultName) {
|
|
return StringLiteral("named results need name: Type for every result");
|
|
}
|
|
if (error == DeclarationError_ResultType) {
|
|
return StringLiteral("a result of a procedure with several results needs a concrete type");
|
|
}
|
|
if (error == DeclarationError_ResultParameters) {
|
|
return StringLiteral("multiple result type parameters exceed the size limit");
|
|
}
|
|
if (error == DeclarationError_ReturnCount) {
|
|
return StringLiteral("return value count does not match the procedure results");
|
|
}
|
|
if (error == DeclarationError_SymmetricParameters) {
|
|
return StringLiteral("#symmetric requires an operator procedure with two parameters");
|
|
}
|
|
if (error == DeclarationError_SymmetricModifier) {
|
|
return StringLiteral("duplicate #symmetric procedure modifier");
|
|
}
|
|
if (error == DeclarationError_ProcedureNameArguments) {
|
|
return StringLiteral("#procedure_name() requires empty parentheses");
|
|
}
|
|
if (error == DeclarationError_BuilderFormat) {
|
|
return StringLiteral("BuilderPrint needs a builder and a literal format");
|
|
}
|
|
if (error == DeclarationError_BuilderPercent) {
|
|
return StringLiteral("BuilderPrint format has more % than arguments");
|
|
}
|
|
if (error == DeclarationError_BuilderArguments) {
|
|
return StringLiteral("BuilderPrint has more arguments than % in its format");
|
|
}
|
|
if (error == DeclarationError_BuilderPrintf) {
|
|
return StringLiteral("BuilderPrint format uses a C or Go conversion such as %d or %s; write a bare % for each argument of any type (%% is one percent sign)");
|
|
}
|
|
if (error == DeclarationError_BuilderPieces) {
|
|
return StringLiteral("BuilderPrint has too many pieces");
|
|
}
|
|
if (error == DeclarationError_BuilderArgumentCount) {
|
|
return StringLiteral("BuilderPrint has too many arguments");
|
|
}
|
|
if (error == DeclarationError_GoVariadic) {
|
|
return StringLiteral("#go_variadic applies once without arguments to an ordinary procedure");
|
|
}
|
|
if (error == DeclarationError_GoMethodQuote) {
|
|
return StringLiteral("#go_method requires a quoted method identifier");
|
|
}
|
|
if (error == DeclarationError_GoMethodDuplicate) {
|
|
return StringLiteral("duplicate #go_method procedure modifier");
|
|
}
|
|
if (error == DeclarationError_GoMethodResults) {
|
|
return StringLiteral("#go_results applies once to a #go_method procedure");
|
|
}
|
|
if (error == DeclarationError_GoMethodForeign) {
|
|
return StringLiteral("#go_method requires an ordinary procedure body");
|
|
}
|
|
return StringLiteral("");
|
|
}
|
|
|
|
GoMethodDeclaration
|
|
declaration_ParseGoMethod(String source, int64_t name_limit)
|
|
{
|
|
GoMethodDeclaration result = {0};
|
|
int64_t opening = declaration_Find(source, StringLiteral("("));
|
|
if (opening < 0LL) {
|
|
return result;
|
|
}
|
|
int64_t closing = source_ClosingParenthesis(StringRangeAt(source, (int64_t)opening, (int64_t)source.length));
|
|
if (closing < 0LL) {
|
|
return result;
|
|
}
|
|
int64_t at = (int64_t)(((uint64_t)opening + (uint64_t)closing) + UINT64_C(1));
|
|
int32_t variadic_count = 0;
|
|
bool variadic_arguments = false;
|
|
int32_t result_count = 0;
|
|
bool result_arguments = false;
|
|
bool foreign = false;
|
|
while (at < (int64_t)(source).length) {
|
|
Scan token = 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("{")) || StringEqual(spelling, StringLiteral(";"))) {
|
|
break;
|
|
}
|
|
at = token.end;
|
|
if (((TokenKind)(token.kind)) != TokenKind_Directive) {
|
|
continue;
|
|
}
|
|
if (StringEqual(spelling, StringLiteral("#foreign"))) {
|
|
foreign = true;
|
|
}
|
|
if (StringEqual(spelling, StringLiteral("#go_variadic"))) {
|
|
variadic_count = (int32_t)((uint32_t)variadic_count + 1u);
|
|
Scan next = scan_NextToken(source, at, 1, 1);
|
|
String following = StringRangeAt(source, (int64_t)next.begin, (int64_t)next.end);
|
|
if (((TokenKind)(next.kind)) != TokenKind_Directive && !StringEqual(following, StringLiteral("{"))) {
|
|
variadic_arguments = true;
|
|
}
|
|
}
|
|
if (StringEqual(spelling, StringLiteral("#go_results"))) {
|
|
result_count = (int32_t)((uint32_t)result_count + 1u);
|
|
Scan next = scan_NextToken(source, at, 1, 1);
|
|
String following = StringRangeAt(source, (int64_t)next.begin, (int64_t)next.end);
|
|
if (((TokenKind)(next.kind)) != TokenKind_Directive && !StringEqual(following, StringLiteral("{"))) {
|
|
result_arguments = true;
|
|
}
|
|
}
|
|
if (!StringEqual(spelling, StringLiteral("#go_method"))) {
|
|
continue;
|
|
}
|
|
if ((int64_t)(result.name).length != 0LL) {
|
|
DeclarationError* value_0 = &(result.error);
|
|
(*value_0) = DeclarationError_GoMethodDuplicate;
|
|
return result;
|
|
}
|
|
int64_t quoted_at = source_text_SkipSpace(source, at, true);
|
|
QuotedText quoted = declaration_UsingQuoted(StringRangeAt(source, (int64_t)quoted_at, (int64_t)source.length), name_limit);
|
|
bool value_1 = !quoted.valid;
|
|
if (!value_1) {
|
|
bool value_2 = source_IdentifierText(quoted.value, false);
|
|
value_1 = !value_2;
|
|
}
|
|
if (value_1) {
|
|
DeclarationError* value_3 = &(result.error);
|
|
(*value_3) = DeclarationError_GoMethodQuote;
|
|
return result;
|
|
}
|
|
String* value_4 = &(result.name);
|
|
(*value_4) = quoted.value;
|
|
at = (int64_t)((uint64_t)quoted_at + (uint64_t)(quoted.end));
|
|
Scan next = scan_NextToken(source, at, 1, 1);
|
|
String following = StringRangeAt(source, (int64_t)next.begin, (int64_t)next.end);
|
|
if (((TokenKind)(next.kind)) != TokenKind_Directive && !StringEqual(following, StringLiteral("{"))) {
|
|
DeclarationError* value_5 = &(result.error);
|
|
(*value_5) = DeclarationError_GoMethodQuote;
|
|
return result;
|
|
}
|
|
}
|
|
if (!foreign) {
|
|
bool* value_6 = &(result.variadic);
|
|
(*value_6) = variadic_count != 0;
|
|
if (variadic_count > 1 || variadic_arguments) {
|
|
DeclarationError* value_7 = &(result.error);
|
|
(*value_7) = DeclarationError_GoVariadic;
|
|
return result;
|
|
}
|
|
}
|
|
if ((int64_t)(result.name).length == 0LL) {
|
|
return result;
|
|
}
|
|
if (foreign) {
|
|
DeclarationError* value_8 = &(result.error);
|
|
(*value_8) = DeclarationError_GoMethodForeign;
|
|
} else if (result_count > 1 || result_arguments) {
|
|
DeclarationError* value_9 = &(result.error);
|
|
(*value_9) = DeclarationError_GoMethodResults;
|
|
}
|
|
bool* value_10 = &(result.results);
|
|
(*value_10) = result_count != 0;
|
|
return result;
|
|
}
|
|
|
|
UsingFilter
|
|
declaration_UsingModifierClause(String source, Slice output, int64_t name_limit)
|
|
{
|
|
UsingFilter result = {0};
|
|
if ((int64_t)(source).length == 0LL || (uint8_t)source.data[0] != 44) {
|
|
return result;
|
|
}
|
|
bool* value_0 = &(result.present);
|
|
(*value_0) = true;
|
|
int64_t at = source_text_SkipSpace(source, 1LL, false);
|
|
String mode = StringRangeAt(source, (int64_t)at, (int64_t)source.length);
|
|
String prefix = StringLiteral("");
|
|
if (source_StartsWord(mode, StringLiteral("only"))) {
|
|
prefix = StringLiteral("O:");
|
|
at = (int64_t)((uint64_t)at + UINT64_C(4));
|
|
} else if (source_StartsWord(mode, StringLiteral("except"))) {
|
|
prefix = StringLiteral("E:");
|
|
at = (int64_t)((uint64_t)at + UINT64_C(6));
|
|
} else if (source_StartsWord(mode, StringLiteral("map"))) {
|
|
prefix = StringLiteral("M:");
|
|
at = (int64_t)((uint64_t)at + UINT64_C(3));
|
|
} else {
|
|
DeclarationError* value_1 = &(result.error);
|
|
(*value_1) = DeclarationError_UsingKind;
|
|
return result;
|
|
}
|
|
at = source_text_SkipSpace(source, at, false);
|
|
if (at >= (int64_t)(source).length || (uint8_t)source.data[at] != 40) {
|
|
DeclarationError* value_2 = &(result.error);
|
|
(*value_2) = DeclarationError_UsingList;
|
|
return result;
|
|
}
|
|
at = source_text_SkipSpace(source, (int64_t)((uint64_t)at + UINT64_C(1)), false);
|
|
declaration_Put(output, &(result.count), prefix);
|
|
int64_t entries = 0LL;
|
|
while (at < (int64_t)(source).length && (uint8_t)source.data[at] != 41) {
|
|
QuotedText quoted = declaration_UsingQuoted(StringRangeAt(source, (int64_t)at, (int64_t)source.length), name_limit);
|
|
if (!quoted.valid) {
|
|
DeclarationError* value_3 = &(result.error);
|
|
(*value_3) = DeclarationError_UsingEntry;
|
|
return result;
|
|
}
|
|
String name = quoted.value;
|
|
at = source_text_SkipSpace(source, (int64_t)((uint64_t)at + (uint64_t)(quoted.end)), false);
|
|
String mapped = StringLiteral("");
|
|
if (StringEqual(prefix, StringLiteral("M:"))) {
|
|
if (at >= (int64_t)(source).length || (uint8_t)source.data[at] != 61) {
|
|
DeclarationError* value_4 = &(result.error);
|
|
(*value_4) = DeclarationError_UsingMap;
|
|
return result;
|
|
}
|
|
at = source_text_SkipSpace(source, (int64_t)((uint64_t)at + UINT64_C(1)), false);
|
|
quoted = declaration_UsingQuoted(StringRangeAt(source, (int64_t)at, (int64_t)source.length), name_limit);
|
|
if (!quoted.valid) {
|
|
DeclarationError* value_5 = &(result.error);
|
|
(*value_5) = DeclarationError_UsingMap;
|
|
return result;
|
|
}
|
|
mapped = quoted.value;
|
|
at = source_text_SkipSpace(source, (int64_t)((uint64_t)at + (uint64_t)(quoted.end)), false);
|
|
}
|
|
if (entries > 0LL) {
|
|
declaration_Put(output, &(result.count), StringLiteral(","));
|
|
}
|
|
declaration_Put(output, &(result.count), name);
|
|
if (StringEqual(prefix, StringLiteral("M:"))) {
|
|
declaration_Put(output, &(result.count), StringLiteral("="));
|
|
declaration_Put(output, &(result.count), mapped);
|
|
}
|
|
entries = (int64_t)((uint64_t)entries + UINT64_C(1));
|
|
if (at >= (int64_t)(source).length || (uint8_t)source.data[at] != 44) {
|
|
break;
|
|
}
|
|
at = source_text_SkipSpace(source, (int64_t)((uint64_t)at + UINT64_C(1)), false);
|
|
}
|
|
if (entries == 0LL || at >= (int64_t)(source).length || (uint8_t)source.data[at] != 41) {
|
|
DeclarationError* value_6 = &(result.error);
|
|
(*value_6) = DeclarationError_UsingList;
|
|
return result;
|
|
}
|
|
int64_t* value_7 = &(result.next);
|
|
int64_t value_8 = source_text_SkipSpace(source, (int64_t)((uint64_t)at + UINT64_C(1)), false);
|
|
(*value_7) = value_8;
|
|
return result;
|
|
}
|
|
|
|
static QuotedText
|
|
declaration_UsingQuoted(String source, int64_t limit)
|
|
{
|
|
if ((int64_t)(source).length == 0LL || (uint8_t)source.data[0] != 34) {
|
|
return (QuotedText){0};
|
|
}
|
|
int64_t at = 1LL;
|
|
while (at < (int64_t)(source).length && (uint8_t)source.data[at] != 34 && (uint8_t)source.data[at] != 0) {
|
|
at = (int64_t)((uint64_t)at + UINT64_C(1));
|
|
}
|
|
if (at == (int64_t)(source).length || (uint8_t)source.data[at] != 34 || at == 1LL || (int64_t)((uint64_t)at - UINT64_C(1)) >= limit) {
|
|
return (QuotedText){0};
|
|
}
|
|
return (QuotedText){.valid = true, .value = StringRangeAt(source, (int64_t)1LL, (int64_t)at), .end = (int64_t)((uint64_t)at + UINT64_C(1))};
|
|
}
|
|
|
|
ExportDirective
|
|
declaration_ProgramExport(String source, int64_t symbol_limit)
|
|
{
|
|
ExportDirective result = {0};
|
|
bool value_0 = source_StartsWord(source, StringLiteral("#program_export"));
|
|
if (!value_0) {
|
|
return result;
|
|
}
|
|
int64_t at = source_text_SkipSpace(source, 15LL, true);
|
|
if (at < (int64_t)(source).length && (uint8_t)source.data[at] == 34) {
|
|
String value_1 = StringRangeAt(source, (int64_t)at, (int64_t)source.length);
|
|
QuotedText value_2 = {0};
|
|
{
|
|
String value_4 = value_1;
|
|
int64_t value_5 = symbol_limit;
|
|
int64_t value_6 = declaration_Find(value_4, StringLiteral("\""));
|
|
if (value_6 < 0LL) {
|
|
value_2 = (QuotedText){0};
|
|
goto value_3;
|
|
}
|
|
int64_t value_7 = declaration_Find(StringRangeAt(value_4, (int64_t)((int64_t)((uint64_t)value_6 + UINT64_C(1))), (int64_t)value_4.length), StringLiteral("\""));
|
|
if (value_7 < 0LL || value_7 >= value_5) {
|
|
value_2 = (QuotedText){0};
|
|
goto value_3;
|
|
}
|
|
value_7 = (int64_t)((uint64_t)value_7 + ((uint64_t)value_6 + UINT64_C(1)));
|
|
value_2 = (QuotedText){.valid = true, .value = StringRangeAt(value_4, (int64_t)((int64_t)((uint64_t)value_6 + UINT64_C(1))), (int64_t)value_7), .end = (int64_t)((uint64_t)value_7 + UINT64_C(1))};
|
|
value_3: ;
|
|
}
|
|
QuotedText quoted = value_2;
|
|
if (!quoted.valid) {
|
|
DeclarationError* value_8 = &(result.error);
|
|
(*value_8) = DeclarationError_ExportQuote;
|
|
return result;
|
|
}
|
|
String* value_9 = &(result.symbol);
|
|
(*value_9) = quoted.value;
|
|
bool value_10 = source_IdentifierText(result.symbol, false);
|
|
if (!value_10) {
|
|
DeclarationError* value_11 = &(result.error);
|
|
(*value_11) = DeclarationError_ExportName;
|
|
return result;
|
|
}
|
|
at = source_text_SkipSpace(source, (int64_t)((uint64_t)at + (uint64_t)(quoted.end)), true);
|
|
}
|
|
int32_t* value_12 = &(result.kind);
|
|
(*value_12) = 1;
|
|
if (at < (int64_t)(source).length) {
|
|
int32_t* value_13 = &(result.kind);
|
|
(*value_13) = 2;
|
|
}
|
|
String* value_14 = &(result.body);
|
|
(*value_14) = StringRangeAt(source, (int64_t)at, (int64_t)source.length);
|
|
return result;
|
|
}
|
|
|
|
ParameterRewrite
|
|
declaration_RewriteParameters(String source, Slice output, bool strip_defaults, bool strip_using, int64_t name_limit)
|
|
{
|
|
ParameterRewrite result = {0};
|
|
int64_t value_0 = source_text_SkipSpace(source, 0LL, true);
|
|
int64_t value_1 = (int64_t)(source).length;
|
|
if (value_0 == value_1) {
|
|
return result;
|
|
}
|
|
int64_t at = 0LL;
|
|
while (at >= 0LL) {
|
|
if (result.parameters == 64) {
|
|
DeclarationError* value_2 = &(result.error);
|
|
(*value_2) = DeclarationError_Parameters;
|
|
return result;
|
|
}
|
|
SourcePart range = source_text_NextSourcePart(source, at);
|
|
String value_3 = StringRangeAt(source, (int64_t)range.begin, (int64_t)range.end);
|
|
String value_4 = StringView(NULL, 0);
|
|
{
|
|
String value_6 = value_3;
|
|
SourceRange value_7 = source_text_TrimRange(value_6);
|
|
value_4 = StringRangeAt(value_6, (int64_t)value_7.begin, (int64_t)value_7.end);
|
|
}
|
|
String part = value_4;
|
|
if (strip_defaults) {
|
|
int64_t assignment = source_text_TopLevelAssignment(part);
|
|
if (assignment >= 0LL) {
|
|
int64_t value_8 = source_text_SkipSpace(part, (int64_t)((uint64_t)assignment + UINT64_C(1)), true);
|
|
int64_t value_9 = (int64_t)(part).length;
|
|
if (value_8 == value_9) {
|
|
DeclarationError* value_10 = &(result.error);
|
|
(*value_10) = DeclarationError_DefaultValue;
|
|
return result;
|
|
}
|
|
String value_11 = StringRangeAt(part, (int64_t)0LL, (int64_t)assignment);
|
|
String value_12 = StringView(NULL, 0);
|
|
{
|
|
String value_14 = value_11;
|
|
SourceRange value_15 = source_text_TrimRange(value_14);
|
|
value_12 = StringRangeAt(value_14, (int64_t)value_15.begin, (int64_t)value_15.end);
|
|
}
|
|
part = value_12;
|
|
bool* value_16 = &(result.has_defaults);
|
|
(*value_16) = true;
|
|
}
|
|
}
|
|
if (strip_using && source_StartsWord(part, StringLiteral("using"))) {
|
|
bool value_17 = (int64_t)(part).length <= 5LL;
|
|
if (!value_17) {
|
|
bool value_18 = source_text_SpaceByte((uint8_t)part.data[5]);
|
|
value_17 = !value_18;
|
|
}
|
|
if (value_17) {
|
|
DeclarationError* value_19 = &(result.error);
|
|
(*value_19) = DeclarationError_UsingModifier;
|
|
return result;
|
|
}
|
|
String value_20 = StringRangeAt(part, (int64_t)5LL, (int64_t)part.length);
|
|
String value_21 = StringView(NULL, 0);
|
|
{
|
|
String value_23 = value_20;
|
|
SourceRange value_24 = source_text_TrimRange(value_23);
|
|
value_21 = StringRangeAt(value_23, (int64_t)value_24.begin, (int64_t)value_24.end);
|
|
}
|
|
part = value_21;
|
|
int64_t colon = declaration_Find(part, StringLiteral(":"));
|
|
if (colon <= 0LL || colon >= name_limit) {
|
|
DeclarationError* value_25 = &(result.error);
|
|
(*value_25) = DeclarationError_UsingType;
|
|
return result;
|
|
}
|
|
String value_26 = StringRangeAt(part, (int64_t)0LL, (int64_t)colon);
|
|
String value_27 = StringView(NULL, 0);
|
|
{
|
|
String value_29 = value_26;
|
|
SourceRange value_30 = source_text_TrimRange(value_29);
|
|
value_27 = StringRangeAt(value_29, (int64_t)value_30.begin, (int64_t)value_30.end);
|
|
}
|
|
bool value_31 = source_IdentifierText(value_27, false);
|
|
if (!value_31) {
|
|
DeclarationError* value_32 = &(result.error);
|
|
(*value_32) = DeclarationError_UsingName;
|
|
return result;
|
|
}
|
|
uint64_t* value_33 = &(result.using_parameters);
|
|
(*value_33) = (uint64_t)((uint64_t)((*value_33)) | (uint64_t)((ZiShl64(1ULL, (uint64_t)((uint64_t)(result.parameters)), 64))));
|
|
}
|
|
if (result.parameters > 0) {
|
|
declaration_Put(output, &(result.count), StringLiteral(", "));
|
|
}
|
|
declaration_Put(output, &(result.count), part);
|
|
int32_t* value_34 = &(result.parameters);
|
|
(*value_34) = (int32_t)((uint32_t)((*value_34)) + 1u);
|
|
at = range.next;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
ParameterRewrite
|
|
declaration_RewriteProcedureTypeParameters(String source, Slice output, int64_t name_limit)
|
|
{
|
|
ParameterRewrite result = {0};
|
|
int64_t value_0 = source_text_SkipSpace(source, 0LL, true);
|
|
int64_t value_1 = (int64_t)(source).length;
|
|
if (value_0 == value_1) {
|
|
return result;
|
|
}
|
|
int64_t at = 0LL;
|
|
while (at >= 0LL) {
|
|
if (result.parameters == 16) {
|
|
DeclarationError* value_2 = &(result.error);
|
|
(*value_2) = DeclarationError_ProcedureTypeCount;
|
|
return result;
|
|
}
|
|
SourcePart range = source_text_NextSourcePart(source, at);
|
|
String value_3 = StringRangeAt(source, (int64_t)range.begin, (int64_t)range.end);
|
|
String value_4 = StringView(NULL, 0);
|
|
{
|
|
String value_6 = value_3;
|
|
SourceRange value_7 = source_text_TrimRange(value_6);
|
|
value_4 = StringRangeAt(value_6, (int64_t)value_7.begin, (int64_t)value_7.end);
|
|
}
|
|
String part = value_4;
|
|
int64_t value_8 = source_text_TopLevelAssignment(part);
|
|
if (value_8 >= 0LL) {
|
|
DeclarationError* value_9 = &(result.error);
|
|
(*value_9) = DeclarationError_ProcedureTypeDefault;
|
|
return result;
|
|
}
|
|
int64_t colon = declaration_Find(part, StringLiteral(":"));
|
|
String type = part;
|
|
if (result.parameters > 0) {
|
|
declaration_Put(output, &(result.count), StringLiteral(", "));
|
|
}
|
|
if (colon >= 0LL) {
|
|
String value_10 = StringRangeAt(part, (int64_t)0LL, (int64_t)colon);
|
|
String value_11 = StringView(NULL, 0);
|
|
{
|
|
String value_13 = value_10;
|
|
SourceRange value_14 = source_text_TrimRange(value_13);
|
|
value_11 = StringRangeAt(value_13, (int64_t)value_14.begin, (int64_t)value_14.end);
|
|
}
|
|
String name = value_11;
|
|
bool value_15 = (int64_t)(name).length >= name_limit;
|
|
if (!value_15) {
|
|
bool value_16 = source_IdentifierText(name, false);
|
|
value_15 = !value_16;
|
|
}
|
|
if (value_15) {
|
|
DeclarationError* value_17 = &(result.error);
|
|
(*value_17) = DeclarationError_ProcedureTypeName;
|
|
return result;
|
|
}
|
|
declaration_Put(output, &(result.count), name);
|
|
String value_18 = StringRangeAt(part, (int64_t)((int64_t)((uint64_t)colon + UINT64_C(1))), (int64_t)part.length);
|
|
String value_19 = StringView(NULL, 0);
|
|
{
|
|
String value_21 = value_18;
|
|
SourceRange value_22 = source_text_TrimRange(value_21);
|
|
value_19 = StringRangeAt(value_21, (int64_t)value_22.begin, (int64_t)value_22.end);
|
|
}
|
|
type = value_19;
|
|
} else {
|
|
declaration_Put(output, &(result.count), StringLiteral("arg"));
|
|
uint8_t digits[2] = {0};
|
|
int64_t length = 0LL;
|
|
if (result.parameters >= 10) {
|
|
uint8_t* value_23 = &(digits[length]);
|
|
(*value_23) = 49;
|
|
length = (int64_t)((uint64_t)length + UINT64_C(1));
|
|
}
|
|
uint8_t* value_24 = &(digits[length]);
|
|
(*value_24) = (uint8_t)(48u + (uint32_t)((result.parameters % 10)));
|
|
length = (int64_t)((uint64_t)length + UINT64_C(1));
|
|
Slice value_25 = {digits, 2};
|
|
Slice value_26 = SliceRangeAt(value_25, (int64_t)0LL, (int64_t)length, sizeof(uint8_t));
|
|
declaration_Put(output, &(result.count), StringView((const char *)(value_26).data, (size_t)(value_26).length));
|
|
}
|
|
bool value_27 = (int64_t)(type).length == 0LL;
|
|
if (!value_27) {
|
|
int64_t value_28 = declaration_Find(type, StringLiteral(":"));
|
|
value_27 = (value_28 >= 0LL);
|
|
}
|
|
if (value_27) {
|
|
DeclarationError* value_29 = &(result.error);
|
|
(*value_29) = DeclarationError_ProcedureTypeType;
|
|
return result;
|
|
}
|
|
declaration_Put(output, &(result.count), StringLiteral(": "));
|
|
declaration_Put(output, &(result.count), type);
|
|
int32_t* value_30 = &(result.parameters);
|
|
(*value_30) = (int32_t)((uint32_t)((*value_30)) + 1u);
|
|
at = range.next;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
ModuleImport
|
|
declaration_ImportDeclaration(String source, int64_t name_limit, int64_t path_limit)
|
|
{
|
|
ModuleImport result = {0};
|
|
int64_t directive = source_FindUnquoted(source, StringLiteral("#import"), false);
|
|
if (directive < 0LL) {
|
|
return result;
|
|
}
|
|
String body = source;
|
|
bool* value_0 = &(result.using_import);
|
|
(*value_0) = source_StartsWord(source, StringLiteral("using"));
|
|
if (result.using_import) {
|
|
String value_1 = source;
|
|
int64_t value_2 = source_text_SkipSpace(source, 5LL, true);
|
|
body = StringRangeAt(value_1, (int64_t)value_2, (int64_t)value_1.length);
|
|
bool value_3 = (int64_t)(body).length == 0LL;
|
|
if (!value_3) {
|
|
bool value_4 = source_IdentifierText(StringRangeAt(body, (int64_t)0LL, (int64_t)1LL), false);
|
|
value_3 = !value_4;
|
|
}
|
|
if (value_3) {
|
|
return result;
|
|
}
|
|
}
|
|
bool* value_5 = &(result.present);
|
|
(*value_5) = true;
|
|
String value_6 = StringRangeAt(source, (int64_t)directive, (int64_t)source.length);
|
|
QuotedText value_7 = {0};
|
|
{
|
|
String value_9 = value_6;
|
|
int64_t value_10 = path_limit;
|
|
int64_t value_11 = declaration_Find(value_9, StringLiteral("\""));
|
|
if (value_11 < 0LL) {
|
|
value_7 = (QuotedText){0};
|
|
goto value_8;
|
|
}
|
|
int64_t value_12 = declaration_Find(StringRangeAt(value_9, (int64_t)((int64_t)((uint64_t)value_11 + UINT64_C(1))), (int64_t)value_9.length), StringLiteral("\""));
|
|
if (value_12 < 0LL || value_12 >= value_10) {
|
|
value_7 = (QuotedText){0};
|
|
goto value_8;
|
|
}
|
|
value_12 = (int64_t)((uint64_t)value_12 + ((uint64_t)value_11 + UINT64_C(1)));
|
|
String value_13 = StringRangeAt(value_9, (int64_t)((int64_t)((uint64_t)value_11 + UINT64_C(1))), (int64_t)value_12);
|
|
value_7 = (QuotedText){.valid = true, .value = value_13, .end = (int64_t)((uint64_t)value_12 + UINT64_C(1))};
|
|
value_8: ;
|
|
}
|
|
QuotedText quoted = value_7;
|
|
if (!quoted.valid) {
|
|
DeclarationError* value_14 = &(result.error);
|
|
(*value_14) = DeclarationError_ImportQuote;
|
|
return result;
|
|
}
|
|
String* value_15 = &(result.target);
|
|
(*value_15) = quoted.value;
|
|
{
|
|
String value_16 = result.target;
|
|
String loop_view_20 = StringRangeAt(value_16, (int64_t)0, (int64_t)value_16.length);
|
|
int64_t loop_count_20 = (int64_t)(loop_view_20).length;
|
|
int64_t loop_cursor_20 = 0LL;
|
|
while (loop_cursor_20 < loop_count_20) {
|
|
int64_t loop_index_20 = loop_cursor_20;
|
|
uint8_t byte = (uint8_t)loop_view_20.data[loop_index_20];
|
|
if (byte == 34 || byte == 62 || byte < 32) {
|
|
DeclarationError* value_17 = &(result.error);
|
|
(*value_17) = DeclarationError_ImportCharacter;
|
|
return result;
|
|
}
|
|
loop_cursor_20 = (int64_t)((uint64_t)loop_cursor_20 + UINT64_C(1));
|
|
}
|
|
}
|
|
String value_18 = source;
|
|
int64_t value_19 = source_text_SkipSpace(source, (int64_t)((uint64_t)directive + UINT64_C(7)), true);
|
|
String mode = StringRangeAt(value_18, (int64_t)value_19, (int64_t)value_18.length);
|
|
if ((int64_t)(mode).length > 0LL && (uint8_t)mode.data[0] == 44) {
|
|
String value_20 = mode;
|
|
int64_t value_21 = source_text_SkipSpace(mode, 1LL, true);
|
|
mode = StringRangeAt(value_20, (int64_t)value_21, (int64_t)value_20.length);
|
|
int64_t keyword = 0LL;
|
|
bool value_22 = (int64_t)(mode).length > 3LL && StringEqual(StringRangeAt(mode, (int64_t)0LL, (int64_t)3LL), StringLiteral("dir"));
|
|
bool value_23 = value_22;
|
|
if (value_23 && source_text_SpaceByte((uint8_t)mode.data[3])) {
|
|
ImportMode* value_24 = &(result.mode);
|
|
(*value_24) = ImportMode_Directory;
|
|
keyword = 3LL;
|
|
} else {
|
|
bool value_25 = (int64_t)(mode).length > 4LL && StringEqual(StringRangeAt(mode, (int64_t)0LL, (int64_t)4LL), StringLiteral("file"));
|
|
bool value_26 = value_25;
|
|
if (value_26 && source_text_SpaceByte((uint8_t)mode.data[4])) {
|
|
ImportMode* value_27 = &(result.mode);
|
|
(*value_27) = ImportMode_File;
|
|
keyword = 4LL;
|
|
} else {
|
|
DeclarationError* value_28 = &(result.error);
|
|
(*value_28) = DeclarationError_ImportMode;
|
|
String* value_29 = &(result.detail);
|
|
(*value_29) = mode;
|
|
return result;
|
|
}
|
|
}
|
|
String value_30 = mode;
|
|
int64_t value_31 = source_text_SkipSpace(mode, keyword, true);
|
|
String argument = StringRangeAt(value_30, (int64_t)value_31, (int64_t)value_30.length);
|
|
QuotedText value_32 = {0};
|
|
{
|
|
String value_34 = argument;
|
|
int64_t value_35 = path_limit;
|
|
int64_t value_36 = declaration_Find(value_34, StringLiteral("\""));
|
|
if (value_36 < 0LL) {
|
|
value_32 = (QuotedText){0};
|
|
goto value_33;
|
|
}
|
|
int64_t value_37 = declaration_Find(StringRangeAt(value_34, (int64_t)((int64_t)((uint64_t)value_36 + UINT64_C(1))), (int64_t)value_34.length), StringLiteral("\""));
|
|
if (value_37 < 0LL || value_37 >= value_35) {
|
|
value_32 = (QuotedText){0};
|
|
goto value_33;
|
|
}
|
|
value_37 = (int64_t)((uint64_t)value_37 + ((uint64_t)value_36 + UINT64_C(1)));
|
|
String value_38 = StringRangeAt(value_34, (int64_t)((int64_t)((uint64_t)value_36 + UINT64_C(1))), (int64_t)value_37);
|
|
value_32 = (QuotedText){.valid = true, .value = value_38, .end = (int64_t)((uint64_t)value_37 + UINT64_C(1))};
|
|
value_33: ;
|
|
}
|
|
QuotedText path = value_32;
|
|
bool value_39 = path.valid && (int64_t)(argument).length > 0LL && (uint8_t)argument.data[0] == 34;
|
|
bool value_40 = value_39;
|
|
if (value_40) {
|
|
String value_41 = argument;
|
|
int64_t value_42 = source_text_SkipSpace(argument, path.end, true);
|
|
uint8_t value_43 = 0;
|
|
{
|
|
String value_45 = value_41;
|
|
int64_t value_46 = value_42;
|
|
if (value_46 < 0LL || value_46 >= (int64_t)(value_45).length) {
|
|
value_43 = 0;
|
|
goto value_44;
|
|
}
|
|
value_43 = (uint8_t)value_45.data[value_46];
|
|
value_44: ;
|
|
}
|
|
value_40 = (value_43 == 40);
|
|
}
|
|
if (value_40) {
|
|
DeclarationError* value_47 = &(result.error);
|
|
(*value_47) = DeclarationError_ImportParameterMode;
|
|
return result;
|
|
}
|
|
bool value_48 = (int64_t)(argument).length == 0LL || (uint8_t)argument.data[0] != 34 || !path.valid;
|
|
bool value_49 = value_48;
|
|
if (!value_49) {
|
|
String value_50 = argument;
|
|
int64_t value_51 = source_text_SkipSpace(argument, path.end, true);
|
|
bool value_52 = !StringEqual(StringRangeAt(value_50, (int64_t)value_51, (int64_t)value_50.length), StringLiteral(";"));
|
|
value_49 = value_52;
|
|
}
|
|
if (value_49) {
|
|
DeclarationError* value_53 = &(result.error);
|
|
(*value_53) = DeclarationError_ImportFileSyntax;
|
|
if (((ImportMode)(result.mode)) == ImportMode_Directory) {
|
|
DeclarationError* value_54 = &(result.error);
|
|
(*value_54) = DeclarationError_ImportDirSyntax;
|
|
}
|
|
return result;
|
|
}
|
|
String* value_55 = &(result.name);
|
|
(*value_55) = declaration_SymbolBeforeColons(body, name_limit);
|
|
bool* value_56 = &(result.named);
|
|
(*value_56) = (int64_t)(result.name).length > 0LL;
|
|
String* value_57 = &(result.path);
|
|
(*value_57) = result.target;
|
|
bool value_58 = (int64_t)(result.path).length > 0LL && (uint8_t)result.path.data[0] != 47;
|
|
bool value_59 = value_58;
|
|
if (value_59) {
|
|
int64_t value_60 = declaration_Find(result.path, StringLiteral("\\"));
|
|
value_59 = (value_60 < 0LL);
|
|
}
|
|
bool valid = value_59 && (uint8_t)result.path.data[((int64_t)((uint64_t)((int64_t)(result.path).length) - UINT64_C(1)))] != 47;
|
|
String stem = declaration_Basename(result.path);
|
|
if (((ImportMode)(result.mode)) == ImportMode_File) {
|
|
int64_t extension = (int64_t)((uint64_t)((int64_t)(stem).length) - UINT64_C(1));
|
|
while (extension >= 0LL && (uint8_t)stem.data[extension] != 46) {
|
|
extension = (int64_t)((uint64_t)extension - UINT64_C(1));
|
|
}
|
|
valid = valid && extension > 0LL;
|
|
if (valid) {
|
|
String suffix = StringRangeAt(stem, (int64_t)extension, (int64_t)stem.length);
|
|
bool value_61 = StringEqual(suffix, StringLiteral(".zi")) || StringEqual(suffix, StringLiteral(".zir")) || StringEqual(suffix, StringLiteral(".ts"));
|
|
bool value_62 = value_61 || StringEqual(suffix, StringLiteral(".tsx")) || StringEqual(suffix, StringLiteral(".mts"));
|
|
valid = value_62 || StringEqual(suffix, StringLiteral(".cts"));
|
|
stem = StringRangeAt(stem, (int64_t)0, (int64_t)extension);
|
|
}
|
|
}
|
|
if (!valid) {
|
|
DeclarationError* value_63 = &(result.error);
|
|
(*value_63) = DeclarationError_ImportFilePath;
|
|
if (((ImportMode)(result.mode)) == ImportMode_Directory) {
|
|
DeclarationError* value_64 = &(result.error);
|
|
(*value_64) = DeclarationError_ImportDirPath;
|
|
}
|
|
return result;
|
|
}
|
|
bool value_65 = (int64_t)(stem).length >= name_limit;
|
|
if (!value_65) {
|
|
bool value_66 = source_IdentifierText(stem, false);
|
|
value_65 = !value_66;
|
|
}
|
|
if (value_65) {
|
|
DeclarationError* value_67 = &(result.error);
|
|
(*value_67) = DeclarationError_ImportFileName;
|
|
if (((ImportMode)(result.mode)) == ImportMode_Directory) {
|
|
DeclarationError* value_68 = &(result.error);
|
|
(*value_68) = DeclarationError_ImportDirName;
|
|
}
|
|
return result;
|
|
}
|
|
if (!result.named) {
|
|
String* value_69 = &(result.name);
|
|
(*value_69) = stem;
|
|
}
|
|
String* value_70 = &(result.target);
|
|
(*value_70) = stem;
|
|
} else {
|
|
String* value_71 = &(result.name);
|
|
(*value_71) = declaration_SymbolBeforeColons(body, name_limit);
|
|
bool* value_72 = &(result.named);
|
|
(*value_72) = (int64_t)(result.name).length > 0LL;
|
|
if (!result.named) {
|
|
String* value_73 = &(result.name);
|
|
(*value_73) = declaration_Basename(result.target);
|
|
if ((int64_t)(result.name).length >= name_limit) {
|
|
DeclarationError* value_74 = &(result.error);
|
|
(*value_74) = DeclarationError_ImportAliasLimit;
|
|
return result;
|
|
}
|
|
}
|
|
String rest = StringRangeAt(source, (int64_t)((int64_t)((uint64_t)directive + (uint64_t)(quoted.end))), (int64_t)source.length);
|
|
String value_75 = rest;
|
|
int64_t value_76 = source_text_SkipSpace(rest, 0LL, true);
|
|
rest = StringRangeAt(value_75, (int64_t)value_76, (int64_t)value_75.length);
|
|
if ((int64_t)(rest).length > 0LL && (uint8_t)rest.data[0] == 40) {
|
|
int64_t close = source_ClosingParenthesis(rest);
|
|
String after = StringLiteral("");
|
|
if (close >= 0LL) {
|
|
String value_77 = StringRangeAt(rest, (int64_t)((int64_t)((uint64_t)close + UINT64_C(1))), (int64_t)rest.length);
|
|
String value_78 = StringView(NULL, 0);
|
|
{
|
|
String value_80 = value_77;
|
|
SourceRange value_81 = source_text_TrimRange(value_80);
|
|
value_78 = StringRangeAt(value_80, (int64_t)value_81.begin, (int64_t)value_81.end);
|
|
}
|
|
after = value_78;
|
|
}
|
|
bool value_82 = close < 0LL;
|
|
if (!value_82) {
|
|
String value_83 = StringRangeAt(rest, (int64_t)1LL, (int64_t)close);
|
|
String value_84 = StringView(NULL, 0);
|
|
{
|
|
String value_86 = value_83;
|
|
SourceRange value_87 = source_text_TrimRange(value_86);
|
|
value_84 = StringRangeAt(value_86, (int64_t)value_87.begin, (int64_t)value_87.end);
|
|
}
|
|
int64_t value_88 = (int64_t)(value_84).length;
|
|
value_82 = (value_88 == 0LL);
|
|
}
|
|
if (value_82 || (!StringEqual(after, StringLiteral("")) && !StringEqual(after, StringLiteral(";")))) {
|
|
DeclarationError* value_89 = &(result.error);
|
|
(*value_89) = DeclarationError_ImportParameterList;
|
|
return result;
|
|
}
|
|
bool* value_90 = &(result.parameterized);
|
|
(*value_90) = true;
|
|
String* value_91 = &(result.parameters);
|
|
(*value_91) = StringRangeAt(rest, (int64_t)1LL, (int64_t)close);
|
|
DeclarationError* value_92 = &(result.error);
|
|
(*value_92) = (DeclarationError)(declaration_ParameterListError(result.parameters, false, name_limit));
|
|
if (((DeclarationError)(result.error)) != DeclarationError_None) {
|
|
return result;
|
|
}
|
|
}
|
|
}
|
|
bool value_93 = result.named;
|
|
if (value_93) {
|
|
String value_94 = result.name;
|
|
bool value_95 = source_IdentifierText(StringRangeAt(value_94, (int64_t)0LL, (int64_t)1LL), false);
|
|
value_93 = !value_95;
|
|
}
|
|
if (value_93) {
|
|
DeclarationError* value_96 = &(result.error);
|
|
(*value_96) = DeclarationError_ImportAlias;
|
|
return result;
|
|
}
|
|
int64_t start = 0LL;
|
|
while (start <= (int64_t)(result.target).length) {
|
|
String value_97 = result.target;
|
|
int64_t slash = declaration_Find(StringRangeAt(value_97, (int64_t)start, (int64_t)value_97.length), StringLiteral("/"));
|
|
int64_t finish = (int64_t)(result.target).length;
|
|
if (slash >= 0LL) {
|
|
finish = (int64_t)((uint64_t)start + (uint64_t)slash);
|
|
}
|
|
String value_98 = result.target;
|
|
bool value_99 = source_IdentifierText(StringRangeAt(value_98, (int64_t)start, (int64_t)finish), false);
|
|
if (!value_99) {
|
|
DeclarationError* value_100 = &(result.error);
|
|
(*value_100) = DeclarationError_ImportTarget;
|
|
return result;
|
|
}
|
|
if (slash < 0LL) {
|
|
break;
|
|
}
|
|
start = (int64_t)((uint64_t)finish + UINT64_C(1));
|
|
}
|
|
if (result.using_import && !result.named) {
|
|
DeclarationError* value_101 = &(result.error);
|
|
(*value_101) = DeclarationError_ImportUsing;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
String
|
|
declaration_ParameterLiteralType(String value)
|
|
{
|
|
if (StringEqual(value, StringLiteral("true")) || StringEqual(value, StringLiteral("false"))) {
|
|
return StringLiteral("bool");
|
|
}
|
|
bool value_0 = (int64_t)(value).length >= 2LL && (uint8_t)value.data[0] == 34;
|
|
bool value_1 = value_0;
|
|
if (value_1) {
|
|
int64_t value_2 = declaration_AfterQuoted(value, 0LL);
|
|
int64_t value_3 = (int64_t)(value).length;
|
|
value_1 = (value_2 == value_3);
|
|
}
|
|
if (value_1 && (uint8_t)value.data[((int64_t)((uint64_t)((int64_t)(value).length) - UINT64_C(1)))] == 34) {
|
|
return StringLiteral("string");
|
|
}
|
|
String digits = value;
|
|
if ((int64_t)(digits).length > 1LL && (uint8_t)digits.data[0] == 45) {
|
|
digits = StringRangeAt(digits, (int64_t)1LL, (int64_t)digits.length);
|
|
}
|
|
LiteralBits value_4 = source_text_IntegerLiteral(digits);
|
|
if (value_4.valid) {
|
|
return StringLiteral("s64");
|
|
}
|
|
bool value_5 = false;
|
|
{
|
|
String value_7 = digits;
|
|
int64_t value_8 = declaration_Digits(value_7, 0LL);
|
|
bool value_9 = value_8 == 0LL;
|
|
if (!value_9) {
|
|
uint8_t value_10 = 0;
|
|
{
|
|
String value_12 = value_7;
|
|
int64_t value_13 = value_8;
|
|
if (value_13 < 0LL || value_13 >= (int64_t)(value_12).length) {
|
|
value_10 = 0;
|
|
goto value_11;
|
|
}
|
|
value_10 = (uint8_t)value_12.data[value_13];
|
|
value_11: ;
|
|
}
|
|
value_9 = (value_10 != 46);
|
|
}
|
|
if (value_9) {
|
|
value_5 = false;
|
|
goto value_6;
|
|
}
|
|
int64_t value_14 = declaration_Digits(value_7, (int64_t)((uint64_t)value_8 + UINT64_C(1)));
|
|
if (value_14 == (int64_t)((uint64_t)value_8 + UINT64_C(1))) {
|
|
value_5 = false;
|
|
goto value_6;
|
|
}
|
|
if (value_14 == (int64_t)(value_7).length) {
|
|
value_5 = true;
|
|
goto value_6;
|
|
}
|
|
if ((uint8_t)value_7.data[value_14] != 101 && (uint8_t)value_7.data[value_14] != 69) {
|
|
value_5 = false;
|
|
goto value_6;
|
|
}
|
|
int64_t value_15 = (int64_t)((uint64_t)value_14 + UINT64_C(1));
|
|
uint8_t value_16 = 0;
|
|
{
|
|
String value_18 = value_7;
|
|
int64_t value_19 = value_15;
|
|
if (value_19 < 0LL || value_19 >= (int64_t)(value_18).length) {
|
|
value_16 = 0;
|
|
goto value_17;
|
|
}
|
|
value_16 = (uint8_t)value_18.data[value_19];
|
|
value_17: ;
|
|
}
|
|
bool value_20 = value_16 == 43;
|
|
if (!value_20) {
|
|
uint8_t value_21 = 0;
|
|
{
|
|
String value_23 = value_7;
|
|
int64_t value_24 = value_15;
|
|
if (value_24 < 0LL || value_24 >= (int64_t)(value_23).length) {
|
|
value_21 = 0;
|
|
goto value_22;
|
|
}
|
|
value_21 = (uint8_t)value_23.data[value_24];
|
|
value_22: ;
|
|
}
|
|
value_20 = (value_21 == 45);
|
|
}
|
|
if (value_20) {
|
|
value_15 = (int64_t)((uint64_t)value_15 + UINT64_C(1));
|
|
}
|
|
int64_t value_25 = declaration_Digits(value_7, value_15);
|
|
value_5 = value_25 > value_15 && value_25 == (int64_t)(value_7).length;
|
|
value_6: ;
|
|
}
|
|
if (value_5) {
|
|
return StringLiteral("float64");
|
|
}
|
|
return StringLiteral("");
|
|
}
|
|
|
|
bool
|
|
declaration_ParameterTypeName(String type)
|
|
{
|
|
bool value_0 = StringEqual(type, StringLiteral("bool")) || StringEqual(type, StringLiteral("string")) || StringEqual(type, StringLiteral("float32"));
|
|
bool value_1 = value_0 || StringEqual(type, StringLiteral("float64"));
|
|
if (!value_1) {
|
|
int64_t value_2 = declaration_IntegerBits(type);
|
|
value_1 = (value_2 > 0LL);
|
|
}
|
|
return value_1;
|
|
}
|
|
|
|
bool
|
|
declaration_ParameterFits(String type, String value)
|
|
{
|
|
String value_0 = value;
|
|
String value_1 = StringView(NULL, 0);
|
|
{
|
|
String value_3 = value_0;
|
|
if (StringEqual(value_3, StringLiteral("true")) || StringEqual(value_3, StringLiteral("false"))) {
|
|
value_1 = StringLiteral("bool");
|
|
goto value_2;
|
|
}
|
|
bool value_4 = (int64_t)(value_3).length >= 2LL && (uint8_t)value_3.data[0] == 34;
|
|
bool value_5 = value_4;
|
|
if (value_5) {
|
|
int64_t value_6 = declaration_AfterQuoted(value_3, 0LL);
|
|
int64_t value_7 = (int64_t)(value_3).length;
|
|
value_5 = (value_6 == value_7);
|
|
}
|
|
if (value_5 && (uint8_t)value_3.data[((int64_t)((uint64_t)((int64_t)(value_3).length) - UINT64_C(1)))] == 34) {
|
|
value_1 = StringLiteral("string");
|
|
goto value_2;
|
|
}
|
|
String value_8 = value_3;
|
|
if ((int64_t)(value_8).length > 1LL && (uint8_t)value_8.data[0] == 45) {
|
|
value_8 = StringRangeAt(value_8, (int64_t)1LL, (int64_t)value_8.length);
|
|
}
|
|
LiteralBits value_9 = source_text_IntegerLiteral(value_8);
|
|
if (value_9.valid) {
|
|
value_1 = StringLiteral("s64");
|
|
goto value_2;
|
|
}
|
|
bool value_10 = false;
|
|
{
|
|
String value_12 = value_8;
|
|
int64_t value_13 = declaration_Digits(value_12, 0LL);
|
|
if (value_13 == 0LL || declaration_Byte(value_12, value_13) != 46) {
|
|
value_10 = false;
|
|
goto value_11;
|
|
}
|
|
int64_t value_14 = declaration_Digits(value_12, (int64_t)((uint64_t)value_13 + UINT64_C(1)));
|
|
if (value_14 == (int64_t)((uint64_t)value_13 + UINT64_C(1))) {
|
|
value_10 = false;
|
|
goto value_11;
|
|
}
|
|
if (value_14 == (int64_t)(value_12).length) {
|
|
value_10 = true;
|
|
goto value_11;
|
|
}
|
|
if ((uint8_t)value_12.data[value_14] != 101 && (uint8_t)value_12.data[value_14] != 69) {
|
|
value_10 = false;
|
|
goto value_11;
|
|
}
|
|
int64_t value_15 = (int64_t)((uint64_t)value_14 + UINT64_C(1));
|
|
bool value_16 = declaration_Byte(value_12, value_15) == 43;
|
|
if (value_16 || declaration_Byte(value_12, value_15) == 45) {
|
|
value_15 = (int64_t)((uint64_t)value_15 + UINT64_C(1));
|
|
}
|
|
int64_t value_17 = declaration_Digits(value_12, value_15);
|
|
value_10 = value_17 > value_15 && value_17 == (int64_t)(value_12).length;
|
|
value_11: ;
|
|
}
|
|
if (value_10) {
|
|
value_1 = StringLiteral("float64");
|
|
goto value_2;
|
|
}
|
|
value_1 = StringLiteral("");
|
|
value_2: ;
|
|
}
|
|
String class = value_1;
|
|
if (StringEqual(type, StringLiteral("bool")) || StringEqual(type, StringLiteral("string"))) {
|
|
return StringEqual(class, type);
|
|
}
|
|
if (StringEqual(type, StringLiteral("float32")) || StringEqual(type, StringLiteral("float64"))) {
|
|
return StringEqual(class, StringLiteral("float64")) || StringEqual(class, StringLiteral("s64"));
|
|
}
|
|
int64_t bits = declaration_IntegerBits(type);
|
|
if (bits == 0LL || !StringEqual(class, StringLiteral("s64"))) {
|
|
return false;
|
|
}
|
|
bool negative = (uint8_t)value.data[0] == 45;
|
|
String value_18 = StringView(NULL, 0);
|
|
if (negative) {
|
|
value_18 = StringRangeAt(value, (int64_t)1LL, (int64_t)value.length);
|
|
} else {
|
|
value_18 = value;
|
|
}
|
|
LiteralBits value_19 = source_text_IntegerLiteral(value_18);
|
|
uint64_t magnitude = value_19.value;
|
|
if ((uint8_t)type.data[0] == 117) {
|
|
if (negative) {
|
|
return magnitude == 0ULL;
|
|
}
|
|
bool value_20 = bits == 64LL;
|
|
if (!value_20) {
|
|
uint64_t value_21 = ZiShl64(1ULL, (uint64_t)((uint64_t)(bits)), 64);
|
|
value_20 = (magnitude < value_21);
|
|
}
|
|
return value_20;
|
|
}
|
|
uint64_t limit = ZiShl64(1ULL, (uint64_t)((uint64_t)(((int64_t)((uint64_t)bits - UINT64_C(1))))), 64);
|
|
if (negative) {
|
|
return magnitude <= limit;
|
|
}
|
|
return magnitude < limit;
|
|
}
|
|
|
|
int64_t
|
|
declaration_ParameterCanonical(String value, Slice output)
|
|
{
|
|
int64_t used = 0LL;
|
|
String value_0 = value;
|
|
String value_1 = StringView(NULL, 0);
|
|
{
|
|
String value_3 = value_0;
|
|
if (StringEqual(value_3, StringLiteral("true")) || StringEqual(value_3, StringLiteral("false"))) {
|
|
value_1 = StringLiteral("bool");
|
|
goto value_2;
|
|
}
|
|
bool value_4 = (int64_t)(value_3).length >= 2LL && (uint8_t)value_3.data[0] == 34;
|
|
bool value_5 = value_4;
|
|
if (value_5) {
|
|
int64_t value_6 = declaration_AfterQuoted(value_3, 0LL);
|
|
int64_t value_7 = (int64_t)(value_3).length;
|
|
value_5 = (value_6 == value_7);
|
|
}
|
|
if (value_5 && (uint8_t)value_3.data[((int64_t)((uint64_t)((int64_t)(value_3).length) - UINT64_C(1)))] == 34) {
|
|
value_1 = StringLiteral("string");
|
|
goto value_2;
|
|
}
|
|
String value_8 = value_3;
|
|
if ((int64_t)(value_8).length > 1LL && (uint8_t)value_8.data[0] == 45) {
|
|
value_8 = StringRangeAt(value_8, (int64_t)1LL, (int64_t)value_8.length);
|
|
}
|
|
LiteralBits value_9 = source_text_IntegerLiteral(value_8);
|
|
if (value_9.valid) {
|
|
value_1 = StringLiteral("s64");
|
|
goto value_2;
|
|
}
|
|
bool value_10 = false;
|
|
{
|
|
String value_12 = value_8;
|
|
int64_t value_13 = declaration_Digits(value_12, 0LL);
|
|
if (value_13 == 0LL || declaration_Byte(value_12, value_13) != 46) {
|
|
value_10 = false;
|
|
goto value_11;
|
|
}
|
|
int64_t value_14 = declaration_Digits(value_12, (int64_t)((uint64_t)value_13 + UINT64_C(1)));
|
|
if (value_14 == (int64_t)((uint64_t)value_13 + UINT64_C(1))) {
|
|
value_10 = false;
|
|
goto value_11;
|
|
}
|
|
if (value_14 == (int64_t)(value_12).length) {
|
|
value_10 = true;
|
|
goto value_11;
|
|
}
|
|
if ((uint8_t)value_12.data[value_14] != 101 && (uint8_t)value_12.data[value_14] != 69) {
|
|
value_10 = false;
|
|
goto value_11;
|
|
}
|
|
int64_t value_15 = (int64_t)((uint64_t)value_14 + UINT64_C(1));
|
|
bool value_16 = declaration_Byte(value_12, value_15) == 43;
|
|
if (value_16 || declaration_Byte(value_12, value_15) == 45) {
|
|
value_15 = (int64_t)((uint64_t)value_15 + UINT64_C(1));
|
|
}
|
|
int64_t value_17 = declaration_Digits(value_12, value_15);
|
|
value_10 = value_17 > value_15 && value_17 == (int64_t)(value_12).length;
|
|
value_11: ;
|
|
}
|
|
if (value_10) {
|
|
value_1 = StringLiteral("float64");
|
|
goto value_2;
|
|
}
|
|
value_1 = StringLiteral("");
|
|
value_2: ;
|
|
}
|
|
if (!StringEqual(value_1, StringLiteral("s64"))) {
|
|
declaration_Put(output, &(used), value);
|
|
int64_t value_18 = 0;
|
|
if (used <= (int64_t)(output).length) {
|
|
value_18 = used;
|
|
} else {
|
|
value_18 = -1LL;
|
|
}
|
|
return value_18;
|
|
}
|
|
bool negative = (uint8_t)value.data[0] == 45;
|
|
String value_19 = StringView(NULL, 0);
|
|
if (negative) {
|
|
value_19 = StringRangeAt(value, (int64_t)1LL, (int64_t)value.length);
|
|
} else {
|
|
value_19 = value;
|
|
}
|
|
LiteralBits value_20 = source_text_IntegerLiteral(value_19);
|
|
uint64_t magnitude = value_20.value;
|
|
uint8_t digits[20] = {0};
|
|
int64_t count = 0LL;
|
|
while (true) {
|
|
uint8_t* value_21 = &(digits[count]);
|
|
(*value_21) = (uint8_t)(48u + (uint32_t)((magnitude % 10ULL)));
|
|
count = (int64_t)((uint64_t)count + UINT64_C(1));
|
|
magnitude = magnitude / 10ULL;
|
|
if (magnitude == 0ULL) {
|
|
break;
|
|
}
|
|
}
|
|
if (negative && !(count == 1LL && (digits)[0] == 48)) {
|
|
declaration_Put(output, &(used), StringLiteral("-"));
|
|
}
|
|
while (count > 0LL) {
|
|
count = (int64_t)((uint64_t)count - UINT64_C(1));
|
|
if (used < (int64_t)(output).length) {
|
|
uint8_t* value_22 = &(((uint8_t *)(output).data)[used]);
|
|
(*value_22) = (digits)[count];
|
|
}
|
|
used = (int64_t)((uint64_t)used + UINT64_C(1));
|
|
}
|
|
int64_t value_23 = 0;
|
|
if (used <= (int64_t)(output).length) {
|
|
value_23 = used;
|
|
} else {
|
|
value_23 = -1LL;
|
|
}
|
|
return value_23;
|
|
}
|
|
|
|
ParameterEntry
|
|
declaration_NextParameter(String list, int64_t at, bool declaration, int64_t name_limit)
|
|
{
|
|
ParameterEntry result = {0};
|
|
if (at < 0LL || at > (int64_t)(list).length) {
|
|
return result;
|
|
}
|
|
SourcePart range = source_text_NextSourcePart(list, at);
|
|
bool* value_0 = &(result.present);
|
|
(*value_0) = true;
|
|
int64_t* value_1 = &(result.next);
|
|
(*value_1) = range.next;
|
|
String value_2 = StringRangeAt(list, (int64_t)range.begin, (int64_t)range.end);
|
|
String value_3 = StringView(NULL, 0);
|
|
{
|
|
String value_5 = value_2;
|
|
SourceRange value_6 = source_text_TrimRange(value_5);
|
|
value_3 = StringRangeAt(value_5, (int64_t)value_6.begin, (int64_t)value_6.end);
|
|
}
|
|
String part = value_3;
|
|
if ((int64_t)(part).length == 0LL) {
|
|
DeclarationError* value_7 = &(result.error);
|
|
DeclarationError value_8 = (DeclarationError)(0);
|
|
if (declaration) {
|
|
value_8 = DeclarationError_ParameterListSyntax;
|
|
} else {
|
|
value_8 = DeclarationError_ImportParameterList;
|
|
}
|
|
(*value_7) = value_8;
|
|
return result;
|
|
}
|
|
int64_t name_end = 0LL;
|
|
while (name_end < (int64_t)(part).length && source_text_IdentifierByte((uint8_t)part.data[name_end])) {
|
|
name_end = (int64_t)((uint64_t)name_end + UINT64_C(1));
|
|
}
|
|
String* value_9 = &(result.name);
|
|
(*value_9) = StringRangeAt(part, (int64_t)0LL, (int64_t)name_end);
|
|
bool value_10 = name_end >= name_limit;
|
|
if (!value_10) {
|
|
bool value_11 = source_IdentifierText(result.name, false);
|
|
value_10 = !value_11;
|
|
}
|
|
if (value_10) {
|
|
DeclarationError* value_12 = &(result.error);
|
|
(*value_12) = DeclarationError_ParameterName;
|
|
return result;
|
|
}
|
|
String value_13 = part;
|
|
int64_t value_14 = source_text_SkipSpace(part, name_end, true);
|
|
String rest = StringRangeAt(value_13, (int64_t)value_14, (int64_t)value_13.length);
|
|
if (!declaration) {
|
|
bool value_15 = (int64_t)(rest).length == 0LL || (uint8_t)rest.data[0] != 61;
|
|
bool value_16 = value_15;
|
|
if (!value_16) {
|
|
uint8_t value_17 = 0;
|
|
{
|
|
String value_19 = rest;
|
|
int64_t value_20 = 1LL;
|
|
if (value_20 < 0LL || value_20 >= (int64_t)(value_19).length) {
|
|
value_17 = 0;
|
|
goto value_18;
|
|
}
|
|
value_17 = (uint8_t)value_19.data[value_20];
|
|
value_18: ;
|
|
}
|
|
value_16 = (value_17 == 61);
|
|
}
|
|
if (value_16) {
|
|
DeclarationError* value_21 = &(result.error);
|
|
DeclarationError value_22 = (DeclarationError)(0);
|
|
if ((int64_t)(rest).length == 0LL || (uint8_t)rest.data[0] == 61) {
|
|
value_22 = DeclarationError_ImportParameterList;
|
|
} else {
|
|
value_22 = DeclarationError_ParameterName;
|
|
}
|
|
(*value_21) = value_22;
|
|
return result;
|
|
}
|
|
String* value_23 = &(result.value);
|
|
String value_24 = StringRangeAt(rest, (int64_t)1LL, (int64_t)rest.length);
|
|
String value_25 = StringView(NULL, 0);
|
|
{
|
|
String value_27 = value_24;
|
|
SourceRange value_28 = source_text_TrimRange(value_27);
|
|
value_25 = StringRangeAt(value_27, (int64_t)value_28.begin, (int64_t)value_28.end);
|
|
}
|
|
(*value_23) = value_25;
|
|
String value_29 = result.value;
|
|
String value_30 = StringView(NULL, 0);
|
|
{
|
|
String value_32 = value_29;
|
|
if (StringEqual(value_32, StringLiteral("true")) || StringEqual(value_32, StringLiteral("false"))) {
|
|
value_30 = StringLiteral("bool");
|
|
goto value_31;
|
|
}
|
|
bool value_33 = (int64_t)(value_32).length >= 2LL && (uint8_t)value_32.data[0] == 34;
|
|
bool value_34 = value_33;
|
|
if (value_34) {
|
|
int64_t value_35 = declaration_AfterQuoted(value_32, 0LL);
|
|
int64_t value_36 = (int64_t)(value_32).length;
|
|
value_34 = (value_35 == value_36);
|
|
}
|
|
if (value_34 && (uint8_t)value_32.data[((int64_t)((uint64_t)((int64_t)(value_32).length) - UINT64_C(1)))] == 34) {
|
|
value_30 = StringLiteral("string");
|
|
goto value_31;
|
|
}
|
|
String value_37 = value_32;
|
|
if ((int64_t)(value_37).length > 1LL && (uint8_t)value_37.data[0] == 45) {
|
|
value_37 = StringRangeAt(value_37, (int64_t)1LL, (int64_t)value_37.length);
|
|
}
|
|
LiteralBits value_38 = source_text_IntegerLiteral(value_37);
|
|
if (value_38.valid) {
|
|
value_30 = StringLiteral("s64");
|
|
goto value_31;
|
|
}
|
|
bool value_39 = false;
|
|
{
|
|
String value_41 = value_37;
|
|
int64_t value_42 = declaration_Digits(value_41, 0LL);
|
|
if (value_42 == 0LL || declaration_Byte(value_41, value_42) != 46) {
|
|
value_39 = false;
|
|
goto value_40;
|
|
}
|
|
int64_t value_43 = declaration_Digits(value_41, (int64_t)((uint64_t)value_42 + UINT64_C(1)));
|
|
if (value_43 == (int64_t)((uint64_t)value_42 + UINT64_C(1))) {
|
|
value_39 = false;
|
|
goto value_40;
|
|
}
|
|
if (value_43 == (int64_t)(value_41).length) {
|
|
value_39 = true;
|
|
goto value_40;
|
|
}
|
|
if ((uint8_t)value_41.data[value_43] != 101 && (uint8_t)value_41.data[value_43] != 69) {
|
|
value_39 = false;
|
|
goto value_40;
|
|
}
|
|
int64_t value_44 = (int64_t)((uint64_t)value_43 + UINT64_C(1));
|
|
bool value_45 = declaration_Byte(value_41, value_44) == 43;
|
|
if (value_45 || declaration_Byte(value_41, value_44) == 45) {
|
|
value_44 = (int64_t)((uint64_t)value_44 + UINT64_C(1));
|
|
}
|
|
int64_t value_46 = declaration_Digits(value_41, value_44);
|
|
value_39 = value_46 > value_44 && value_46 == (int64_t)(value_41).length;
|
|
value_40: ;
|
|
}
|
|
if (value_39) {
|
|
value_30 = StringLiteral("float64");
|
|
goto value_31;
|
|
}
|
|
value_30 = StringLiteral("");
|
|
value_31: ;
|
|
}
|
|
if (StringEqual(value_30, StringLiteral(""))) {
|
|
DeclarationError* value_47 = &(result.error);
|
|
(*value_47) = DeclarationError_ParameterValue;
|
|
}
|
|
return result;
|
|
}
|
|
if ((int64_t)(rest).length == 0LL || (uint8_t)rest.data[0] != 58) {
|
|
DeclarationError* value_48 = &(result.error);
|
|
DeclarationError value_49 = (DeclarationError)(0);
|
|
if ((int64_t)(rest).length == 0LL) {
|
|
value_49 = DeclarationError_ParameterDefault;
|
|
} else {
|
|
value_49 = DeclarationError_ParameterName;
|
|
}
|
|
(*value_48) = value_49;
|
|
return result;
|
|
}
|
|
rest = StringRangeAt(rest, (int64_t)1LL, (int64_t)rest.length);
|
|
if ((int64_t)(rest).length > 0LL && (uint8_t)rest.data[0] == 61) {
|
|
String* value_50 = &(result.value);
|
|
String value_51 = StringRangeAt(rest, (int64_t)1LL, (int64_t)rest.length);
|
|
String value_52 = StringView(NULL, 0);
|
|
{
|
|
String value_54 = value_51;
|
|
SourceRange value_55 = source_text_TrimRange(value_54);
|
|
value_52 = StringRangeAt(value_54, (int64_t)value_55.begin, (int64_t)value_55.end);
|
|
}
|
|
(*value_50) = value_52;
|
|
String* value_56 = &(result.type);
|
|
String value_57 = result.value;
|
|
String value_58 = StringView(NULL, 0);
|
|
{
|
|
String value_60 = value_57;
|
|
if (StringEqual(value_60, StringLiteral("true")) || StringEqual(value_60, StringLiteral("false"))) {
|
|
value_58 = StringLiteral("bool");
|
|
goto value_59;
|
|
}
|
|
bool value_61 = (int64_t)(value_60).length >= 2LL && (uint8_t)value_60.data[0] == 34;
|
|
bool value_62 = value_61;
|
|
if (value_62) {
|
|
int64_t value_63 = declaration_AfterQuoted(value_60, 0LL);
|
|
int64_t value_64 = (int64_t)(value_60).length;
|
|
value_62 = (value_63 == value_64);
|
|
}
|
|
if (value_62 && (uint8_t)value_60.data[((int64_t)((uint64_t)((int64_t)(value_60).length) - UINT64_C(1)))] == 34) {
|
|
value_58 = StringLiteral("string");
|
|
goto value_59;
|
|
}
|
|
String value_65 = value_60;
|
|
if ((int64_t)(value_65).length > 1LL && (uint8_t)value_65.data[0] == 45) {
|
|
value_65 = StringRangeAt(value_65, (int64_t)1LL, (int64_t)value_65.length);
|
|
}
|
|
LiteralBits value_66 = source_text_IntegerLiteral(value_65);
|
|
if (value_66.valid) {
|
|
value_58 = StringLiteral("s64");
|
|
goto value_59;
|
|
}
|
|
bool value_67 = false;
|
|
{
|
|
String value_69 = value_65;
|
|
int64_t value_70 = declaration_Digits(value_69, 0LL);
|
|
if (value_70 == 0LL || declaration_Byte(value_69, value_70) != 46) {
|
|
value_67 = false;
|
|
goto value_68;
|
|
}
|
|
int64_t value_71 = declaration_Digits(value_69, (int64_t)((uint64_t)value_70 + UINT64_C(1)));
|
|
if (value_71 == (int64_t)((uint64_t)value_70 + UINT64_C(1))) {
|
|
value_67 = false;
|
|
goto value_68;
|
|
}
|
|
if (value_71 == (int64_t)(value_69).length) {
|
|
value_67 = true;
|
|
goto value_68;
|
|
}
|
|
if ((uint8_t)value_69.data[value_71] != 101 && (uint8_t)value_69.data[value_71] != 69) {
|
|
value_67 = false;
|
|
goto value_68;
|
|
}
|
|
int64_t value_72 = (int64_t)((uint64_t)value_71 + UINT64_C(1));
|
|
bool value_73 = declaration_Byte(value_69, value_72) == 43;
|
|
if (value_73 || declaration_Byte(value_69, value_72) == 45) {
|
|
value_72 = (int64_t)((uint64_t)value_72 + UINT64_C(1));
|
|
}
|
|
int64_t value_74 = declaration_Digits(value_69, value_72);
|
|
value_67 = value_74 > value_72 && value_74 == (int64_t)(value_69).length;
|
|
value_68: ;
|
|
}
|
|
if (value_67) {
|
|
value_58 = StringLiteral("float64");
|
|
goto value_59;
|
|
}
|
|
value_58 = StringLiteral("");
|
|
value_59: ;
|
|
}
|
|
(*value_56) = value_58;
|
|
if (StringEqual(result.type, StringLiteral(""))) {
|
|
DeclarationError* value_75 = &(result.error);
|
|
(*value_75) = DeclarationError_ParameterValue;
|
|
}
|
|
return result;
|
|
}
|
|
int64_t assignment = source_text_TopLevelAssignment(rest);
|
|
if (assignment < 0LL) {
|
|
String* value_76 = &(result.type);
|
|
String value_77 = StringView(NULL, 0);
|
|
{
|
|
String value_79 = rest;
|
|
SourceRange value_80 = source_text_TrimRange(value_79);
|
|
value_77 = StringRangeAt(value_79, (int64_t)value_80.begin, (int64_t)value_80.end);
|
|
}
|
|
(*value_76) = value_77;
|
|
DeclarationError* value_81 = &(result.error);
|
|
String value_82 = result.type;
|
|
bool value_83 = false;
|
|
{
|
|
String value_85 = value_82;
|
|
bool value_86 = StringEqual(value_85, StringLiteral("bool")) || StringEqual(value_85, StringLiteral("string")) || StringEqual(value_85, StringLiteral("float32"));
|
|
bool value_87 = value_86 || StringEqual(value_85, StringLiteral("float64"));
|
|
if (!value_87) {
|
|
int64_t value_88 = declaration_IntegerBits(value_85);
|
|
value_87 = (value_88 > 0LL);
|
|
}
|
|
value_83 = value_87;
|
|
}
|
|
DeclarationError value_89 = (DeclarationError)(0);
|
|
if (value_83) {
|
|
value_89 = DeclarationError_ParameterDefault;
|
|
} else {
|
|
value_89 = DeclarationError_ParameterType;
|
|
}
|
|
(*value_81) = value_89;
|
|
return result;
|
|
}
|
|
String* value_90 = &(result.type);
|
|
String value_91 = StringRangeAt(rest, (int64_t)0LL, (int64_t)assignment);
|
|
String value_92 = StringView(NULL, 0);
|
|
{
|
|
String value_94 = value_91;
|
|
SourceRange value_95 = source_text_TrimRange(value_94);
|
|
value_92 = StringRangeAt(value_94, (int64_t)value_95.begin, (int64_t)value_95.end);
|
|
}
|
|
(*value_90) = value_92;
|
|
String* value_96 = &(result.value);
|
|
String value_97 = StringRangeAt(rest, (int64_t)((int64_t)((uint64_t)assignment + UINT64_C(1))), (int64_t)rest.length);
|
|
String value_98 = StringView(NULL, 0);
|
|
{
|
|
String value_100 = value_97;
|
|
SourceRange value_101 = source_text_TrimRange(value_100);
|
|
value_98 = StringRangeAt(value_100, (int64_t)value_101.begin, (int64_t)value_101.end);
|
|
}
|
|
(*value_96) = value_98;
|
|
String value_102 = result.type;
|
|
bool value_103 = false;
|
|
{
|
|
String value_105 = value_102;
|
|
bool value_106 = StringEqual(value_105, StringLiteral("bool")) || StringEqual(value_105, StringLiteral("string")) || StringEqual(value_105, StringLiteral("float32"));
|
|
bool value_107 = value_106 || StringEqual(value_105, StringLiteral("float64"));
|
|
if (!value_107) {
|
|
int64_t value_108 = declaration_IntegerBits(value_105);
|
|
value_107 = (value_108 > 0LL);
|
|
}
|
|
value_103 = value_107;
|
|
}
|
|
if (!value_103) {
|
|
DeclarationError* value_109 = &(result.error);
|
|
(*value_109) = DeclarationError_ParameterType;
|
|
} else {
|
|
String value_110 = result.value;
|
|
String value_111 = StringView(NULL, 0);
|
|
{
|
|
String value_113 = value_110;
|
|
if (StringEqual(value_113, StringLiteral("true")) || StringEqual(value_113, StringLiteral("false"))) {
|
|
value_111 = StringLiteral("bool");
|
|
goto value_112;
|
|
}
|
|
bool value_114 = (int64_t)(value_113).length >= 2LL && (uint8_t)value_113.data[0] == 34;
|
|
bool value_115 = value_114;
|
|
if (value_115) {
|
|
int64_t value_116 = declaration_AfterQuoted(value_113, 0LL);
|
|
int64_t value_117 = (int64_t)(value_113).length;
|
|
value_115 = (value_116 == value_117);
|
|
}
|
|
if (value_115 && (uint8_t)value_113.data[((int64_t)((uint64_t)((int64_t)(value_113).length) - UINT64_C(1)))] == 34) {
|
|
value_111 = StringLiteral("string");
|
|
goto value_112;
|
|
}
|
|
String value_118 = value_113;
|
|
if ((int64_t)(value_118).length > 1LL && (uint8_t)value_118.data[0] == 45) {
|
|
value_118 = StringRangeAt(value_118, (int64_t)1LL, (int64_t)value_118.length);
|
|
}
|
|
LiteralBits value_119 = source_text_IntegerLiteral(value_118);
|
|
if (value_119.valid) {
|
|
value_111 = StringLiteral("s64");
|
|
goto value_112;
|
|
}
|
|
bool value_120 = false;
|
|
{
|
|
String value_122 = value_118;
|
|
int64_t value_123 = declaration_Digits(value_122, 0LL);
|
|
if (value_123 == 0LL || declaration_Byte(value_122, value_123) != 46) {
|
|
value_120 = false;
|
|
goto value_121;
|
|
}
|
|
int64_t value_124 = declaration_Digits(value_122, (int64_t)((uint64_t)value_123 + UINT64_C(1)));
|
|
if (value_124 == (int64_t)((uint64_t)value_123 + UINT64_C(1))) {
|
|
value_120 = false;
|
|
goto value_121;
|
|
}
|
|
if (value_124 == (int64_t)(value_122).length) {
|
|
value_120 = true;
|
|
goto value_121;
|
|
}
|
|
if ((uint8_t)value_122.data[value_124] != 101 && (uint8_t)value_122.data[value_124] != 69) {
|
|
value_120 = false;
|
|
goto value_121;
|
|
}
|
|
int64_t value_125 = (int64_t)((uint64_t)value_124 + UINT64_C(1));
|
|
bool value_126 = declaration_Byte(value_122, value_125) == 43;
|
|
if (value_126 || declaration_Byte(value_122, value_125) == 45) {
|
|
value_125 = (int64_t)((uint64_t)value_125 + UINT64_C(1));
|
|
}
|
|
int64_t value_127 = declaration_Digits(value_122, value_125);
|
|
value_120 = value_127 > value_125 && value_127 == (int64_t)(value_122).length;
|
|
value_121: ;
|
|
}
|
|
if (value_120) {
|
|
value_111 = StringLiteral("float64");
|
|
goto value_112;
|
|
}
|
|
value_111 = StringLiteral("");
|
|
value_112: ;
|
|
}
|
|
if (StringEqual(value_111, StringLiteral(""))) {
|
|
DeclarationError* value_128 = &(result.error);
|
|
(*value_128) = DeclarationError_ParameterValue;
|
|
} else {
|
|
String value_129 = result.type;
|
|
String value_130 = result.value;
|
|
bool value_131 = false;
|
|
{
|
|
String value_133 = value_129;
|
|
String value_134 = value_130;
|
|
String value_135 = StringView(NULL, 0);
|
|
{
|
|
String value_137 = value_134;
|
|
if (StringEqual(value_137, StringLiteral("true")) || StringEqual(value_137, StringLiteral("false"))) {
|
|
value_135 = StringLiteral("bool");
|
|
goto value_136;
|
|
}
|
|
bool value_138 = (int64_t)(value_137).length >= 2LL && (uint8_t)value_137.data[0] == 34;
|
|
bool value_139 = value_138;
|
|
if (value_139) {
|
|
int64_t value_140 = declaration_AfterQuoted(value_137, 0LL);
|
|
int64_t value_141 = (int64_t)(value_137).length;
|
|
value_139 = (value_140 == value_141);
|
|
}
|
|
if (value_139 && (uint8_t)value_137.data[((int64_t)((uint64_t)((int64_t)(value_137).length) - UINT64_C(1)))] == 34) {
|
|
value_135 = StringLiteral("string");
|
|
goto value_136;
|
|
}
|
|
String value_142 = value_137;
|
|
if ((int64_t)(value_142).length > 1LL && (uint8_t)value_142.data[0] == 45) {
|
|
value_142 = StringRangeAt(value_142, (int64_t)1LL, (int64_t)value_142.length);
|
|
}
|
|
LiteralBits value_143 = source_text_IntegerLiteral(value_142);
|
|
if (value_143.valid) {
|
|
value_135 = StringLiteral("s64");
|
|
goto value_136;
|
|
}
|
|
if (declaration_FloatLiteral(value_142)) {
|
|
value_135 = StringLiteral("float64");
|
|
goto value_136;
|
|
}
|
|
value_135 = StringLiteral("");
|
|
value_136: ;
|
|
}
|
|
String value_144 = value_135;
|
|
if (StringEqual(value_133, StringLiteral("bool")) || StringEqual(value_133, StringLiteral("string"))) {
|
|
value_131 = StringEqual(value_144, value_133);
|
|
goto value_132;
|
|
}
|
|
if (StringEqual(value_133, StringLiteral("float32")) || StringEqual(value_133, StringLiteral("float64"))) {
|
|
value_131 = StringEqual(value_144, StringLiteral("float64")) || StringEqual(value_144, StringLiteral("s64"));
|
|
goto value_132;
|
|
}
|
|
int64_t value_145 = declaration_IntegerBits(value_133);
|
|
if (value_145 == 0LL || !StringEqual(value_144, StringLiteral("s64"))) {
|
|
value_131 = false;
|
|
goto value_132;
|
|
}
|
|
bool value_146 = (uint8_t)value_134.data[0] == 45;
|
|
String value_147 = StringView(NULL, 0);
|
|
if (value_146) {
|
|
value_147 = StringRangeAt(value_134, (int64_t)1LL, (int64_t)value_134.length);
|
|
} else {
|
|
value_147 = value_134;
|
|
}
|
|
LiteralBits value_148 = source_text_IntegerLiteral(value_147);
|
|
uint64_t value_149 = value_148.value;
|
|
if ((uint8_t)value_133.data[0] == 117) {
|
|
if (value_146) {
|
|
value_131 = value_149 == 0ULL;
|
|
goto value_132;
|
|
}
|
|
bool value_150 = value_145 == 64LL;
|
|
if (!value_150) {
|
|
uint64_t value_151 = ZiShl64(1ULL, (uint64_t)((uint64_t)(value_145)), 64);
|
|
value_150 = (value_149 < value_151);
|
|
}
|
|
value_131 = value_150;
|
|
goto value_132;
|
|
}
|
|
uint64_t value_152 = ZiShl64(1ULL, (uint64_t)((uint64_t)(((int64_t)((uint64_t)value_145 - UINT64_C(1))))), 64);
|
|
if (value_146) {
|
|
value_131 = value_149 <= value_152;
|
|
goto value_132;
|
|
}
|
|
value_131 = value_149 < value_152;
|
|
value_132: ;
|
|
}
|
|
if (!value_131) {
|
|
DeclarationError* value_153 = &(result.error);
|
|
(*value_153) = DeclarationError_ParameterFit;
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
DeclarationError
|
|
declaration_ParameterListError(String list, bool declaration, int64_t name_limit)
|
|
{
|
|
int64_t at = 0LL;
|
|
while (at >= 0LL) {
|
|
ParameterEntry entry = declaration_NextParameter(list, at, declaration, name_limit);
|
|
if (((DeclarationError)(entry.error)) != DeclarationError_None) {
|
|
return (DeclarationError)(entry.error);
|
|
}
|
|
int64_t earlier = 0LL;
|
|
while (earlier >= 0LL && earlier < at) {
|
|
ParameterEntry previous = declaration_NextParameter(list, earlier, declaration, name_limit);
|
|
if (StringEqual(previous.name, entry.name)) {
|
|
return DeclarationError_ParameterDuplicate;
|
|
}
|
|
earlier = previous.next;
|
|
}
|
|
at = entry.next;
|
|
}
|
|
return DeclarationError_None;
|
|
}
|
|
|
|
InsertDirective
|
|
declaration_InsertDeclaration(String source, int64_t name_limit)
|
|
{
|
|
InsertDirective result = {0};
|
|
bool value_0 = source_StartsWord(source, StringLiteral("#insert"));
|
|
if (!value_0) {
|
|
return result;
|
|
}
|
|
bool* value_1 = &(result.present);
|
|
(*value_1) = true;
|
|
int64_t at = source_text_SkipSpace(source, 7LL, true);
|
|
int64_t end = at;
|
|
while (end < (int64_t)(source).length && source_text_IdentifierByte((uint8_t)source.data[end])) {
|
|
end = (int64_t)((uint64_t)end + UINT64_C(1));
|
|
}
|
|
String* value_2 = &(result.name);
|
|
(*value_2) = StringRangeAt(source, (int64_t)at, (int64_t)end);
|
|
String value_3 = source;
|
|
int64_t value_4 = source_text_SkipSpace(source, end, true);
|
|
String rest = StringRangeAt(value_3, (int64_t)value_4, (int64_t)value_3.length);
|
|
bool value_5 = (int64_t)(result.name).length >= name_limit;
|
|
if (!value_5) {
|
|
bool value_6 = source_IdentifierText(result.name, false);
|
|
value_5 = !value_6;
|
|
}
|
|
if (value_5 || (int64_t)(rest).length == 0LL || (uint8_t)rest.data[0] != 59) {
|
|
DeclarationError* value_7 = &(result.error);
|
|
(*value_7) = DeclarationError_InsertSyntax;
|
|
return result;
|
|
}
|
|
String value_8 = StringRangeAt(rest, (int64_t)1LL, (int64_t)rest.length);
|
|
String value_9 = StringView(NULL, 0);
|
|
{
|
|
String value_11 = value_8;
|
|
SourceRange value_12 = source_text_TrimRange(value_11);
|
|
value_9 = StringRangeAt(value_11, (int64_t)value_12.begin, (int64_t)value_12.end);
|
|
}
|
|
rest = value_9;
|
|
bool value_13 = (int64_t)(rest).length > 0LL;
|
|
if (value_13) {
|
|
bool value_14 = (int64_t)(rest).length >= 2LL && StringEqual(StringRangeAt(rest, (int64_t)0LL, (int64_t)2LL), StringLiteral("//"));
|
|
value_13 = !value_14;
|
|
}
|
|
if (value_13) {
|
|
DeclarationError* value_15 = &(result.error);
|
|
(*value_15) = DeclarationError_InsertSyntax;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
ModuleParameterDirective
|
|
declaration_ModuleParametersPrefix(String source, int64_t name_limit)
|
|
{
|
|
ModuleParameterDirective result = {0};
|
|
int64_t at = 0LL;
|
|
int64_t line = 1LL;
|
|
if ((int64_t)(source).length >= 2LL && StringEqual(StringRangeAt(source, (int64_t)0LL, (int64_t)2LL), StringLiteral("#!"))) {
|
|
while (at < (int64_t)(source).length && (uint8_t)source.data[at] != 10) {
|
|
at = (int64_t)((uint64_t)at + UINT64_C(1));
|
|
}
|
|
}
|
|
while (at < (int64_t)(source).length) {
|
|
uint8_t byte = (uint8_t)source.data[at];
|
|
if (byte == 10) {
|
|
line = (int64_t)((uint64_t)line + UINT64_C(1));
|
|
at = (int64_t)((uint64_t)at + UINT64_C(1));
|
|
} else if (source_text_SpaceByte(byte)) {
|
|
at = (int64_t)((uint64_t)at + UINT64_C(1));
|
|
} else {
|
|
bool value_0 = byte == 47;
|
|
if (value_0) {
|
|
String value_1 = source;
|
|
int64_t value_2 = (int64_t)((uint64_t)at + UINT64_C(1));
|
|
uint8_t value_3 = 0;
|
|
{
|
|
String value_5 = value_1;
|
|
int64_t value_6 = value_2;
|
|
if (value_6 < 0LL || value_6 >= (int64_t)(value_5).length) {
|
|
value_3 = 0;
|
|
goto value_4;
|
|
}
|
|
value_3 = (uint8_t)value_5.data[value_6];
|
|
value_4: ;
|
|
}
|
|
value_0 = (value_3 == 47);
|
|
}
|
|
if (value_0) {
|
|
while (at < (int64_t)(source).length && (uint8_t)source.data[at] != 10) {
|
|
at = (int64_t)((uint64_t)at + UINT64_C(1));
|
|
}
|
|
} else {
|
|
bool value_7 = byte == 47;
|
|
if (value_7) {
|
|
String value_8 = source;
|
|
int64_t value_9 = (int64_t)((uint64_t)at + UINT64_C(1));
|
|
uint8_t value_10 = 0;
|
|
{
|
|
String value_12 = value_8;
|
|
int64_t value_13 = value_9;
|
|
if (value_13 < 0LL || value_13 >= (int64_t)(value_12).length) {
|
|
value_10 = 0;
|
|
goto value_11;
|
|
}
|
|
value_10 = (uint8_t)value_12.data[value_13];
|
|
value_11: ;
|
|
}
|
|
value_7 = (value_10 == 42);
|
|
}
|
|
if (value_7) {
|
|
int32_t depth = 0;
|
|
while (at < (int64_t)(source).length) {
|
|
bool value_14 = (uint8_t)source.data[at] == 47;
|
|
bool value_15 = value_14;
|
|
if (value_15) {
|
|
String value_16 = source;
|
|
int64_t value_17 = (int64_t)((uint64_t)at + UINT64_C(1));
|
|
uint8_t value_18 = 0;
|
|
{
|
|
String value_20 = value_16;
|
|
int64_t value_21 = value_17;
|
|
if (value_21 < 0LL || value_21 >= (int64_t)(value_20).length) {
|
|
value_18 = 0;
|
|
goto value_19;
|
|
}
|
|
value_18 = (uint8_t)value_20.data[value_21];
|
|
value_19: ;
|
|
}
|
|
value_15 = (value_18 == 42);
|
|
}
|
|
if (value_15) {
|
|
depth = (int32_t)((uint32_t)depth + 1u);
|
|
at = (int64_t)((uint64_t)at + UINT64_C(2));
|
|
} else {
|
|
bool value_22 = (uint8_t)source.data[at] == 42;
|
|
bool value_23 = value_22;
|
|
if (value_23) {
|
|
String value_24 = source;
|
|
int64_t value_25 = (int64_t)((uint64_t)at + UINT64_C(1));
|
|
uint8_t value_26 = 0;
|
|
{
|
|
String value_28 = value_24;
|
|
int64_t value_29 = value_25;
|
|
if (value_29 < 0LL || value_29 >= (int64_t)(value_28).length) {
|
|
value_26 = 0;
|
|
goto value_27;
|
|
}
|
|
value_26 = (uint8_t)value_28.data[value_29];
|
|
value_27: ;
|
|
}
|
|
value_23 = (value_26 == 47);
|
|
}
|
|
if (value_23) {
|
|
depth = (int32_t)((uint32_t)depth - 1u);
|
|
at = (int64_t)((uint64_t)at + UINT64_C(2));
|
|
if (depth == 0) {
|
|
break;
|
|
}
|
|
} else {
|
|
if ((uint8_t)source.data[at] == 10) {
|
|
line = (int64_t)((uint64_t)line + UINT64_C(1));
|
|
}
|
|
at = (int64_t)((uint64_t)at + UINT64_C(1));
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
String directive = StringLiteral("#module_parameters");
|
|
bool value_30 = (int64_t)((uint64_t)at + (uint64_t)((int64_t)(directive).length)) > (int64_t)(source).length || !StringEqual(StringRangeAt(source, (int64_t)at, (int64_t)((int64_t)((uint64_t)at + (uint64_t)((int64_t)(directive).length)))), directive);
|
|
bool value_31 = value_30;
|
|
bool value_32 = value_31;
|
|
if (!value_32) {
|
|
String value_33 = source;
|
|
int64_t value_34 = (int64_t)((uint64_t)at + (uint64_t)((int64_t)(directive).length));
|
|
uint8_t value_35 = 0;
|
|
{
|
|
String value_37 = value_33;
|
|
int64_t value_38 = value_34;
|
|
if (value_38 < 0LL || value_38 >= (int64_t)(value_37).length) {
|
|
value_35 = 0;
|
|
goto value_36;
|
|
}
|
|
value_35 = (uint8_t)value_37.data[value_38];
|
|
value_36: ;
|
|
}
|
|
bool value_39 = source_text_IdentifierByte(value_35);
|
|
value_32 = value_39;
|
|
}
|
|
if (value_32) {
|
|
return result;
|
|
}
|
|
bool* value_40 = &(result.present);
|
|
(*value_40) = true;
|
|
int64_t* value_41 = &(result.line);
|
|
(*value_41) = line;
|
|
at = source_text_SkipSpace(source, (int64_t)((uint64_t)at + (uint64_t)((int64_t)(directive).length)), true);
|
|
int64_t close = source_ClosingParenthesis(StringRangeAt(source, (int64_t)at, (int64_t)source.length));
|
|
if (close < 0LL) {
|
|
DeclarationError* value_42 = &(result.error);
|
|
(*value_42) = DeclarationError_ParameterListSyntax;
|
|
return result;
|
|
}
|
|
String* value_43 = &(result.list);
|
|
(*value_43) = StringRangeAt(source, (int64_t)((int64_t)((uint64_t)at + UINT64_C(1))), (int64_t)((int64_t)((uint64_t)at + (uint64_t)close)));
|
|
int64_t after = source_text_SkipSpace(source, (int64_t)(((uint64_t)at + (uint64_t)close) + UINT64_C(1)), true);
|
|
String value_44 = source;
|
|
uint8_t value_45 = 0;
|
|
{
|
|
String value_47 = value_44;
|
|
int64_t value_48 = after;
|
|
if (value_48 < 0LL || value_48 >= (int64_t)(value_47).length) {
|
|
value_45 = 0;
|
|
goto value_46;
|
|
}
|
|
value_45 = (uint8_t)value_47.data[value_48];
|
|
value_46: ;
|
|
}
|
|
if (value_45 == 59) {
|
|
after = source_text_SkipSpace(source, (int64_t)((uint64_t)after + UINT64_C(1)), true);
|
|
}
|
|
bool value_49 = after < (int64_t)(source).length && (uint8_t)source.data[after] != 10 && (uint8_t)source.data[after] != 13;
|
|
bool value_50 = value_49;
|
|
bool value_51 = value_50;
|
|
if (value_51) {
|
|
bool value_52 = (uint8_t)source.data[after] == 47;
|
|
bool value_53 = value_52;
|
|
if (value_53) {
|
|
String value_54 = source;
|
|
int64_t value_55 = (int64_t)((uint64_t)after + UINT64_C(1));
|
|
uint8_t value_56 = 0;
|
|
{
|
|
String value_58 = value_54;
|
|
int64_t value_59 = value_55;
|
|
if (value_59 < 0LL || value_59 >= (int64_t)(value_58).length) {
|
|
value_56 = 0;
|
|
goto value_57;
|
|
}
|
|
value_56 = (uint8_t)value_58.data[value_59];
|
|
value_57: ;
|
|
}
|
|
value_53 = (value_56 == 47);
|
|
}
|
|
value_51 = !value_53;
|
|
}
|
|
if (value_51) {
|
|
DeclarationError* value_60 = &(result.error);
|
|
(*value_60) = DeclarationError_ParameterListSyntax;
|
|
return result;
|
|
}
|
|
String value_61 = result.list;
|
|
String value_62 = StringView(NULL, 0);
|
|
{
|
|
String value_64 = value_61;
|
|
SourceRange value_65 = source_text_TrimRange(value_64);
|
|
value_62 = StringRangeAt(value_64, (int64_t)value_65.begin, (int64_t)value_65.end);
|
|
}
|
|
int64_t value_66 = (int64_t)(value_62).length;
|
|
if (value_66 == 0LL) {
|
|
DeclarationError* value_67 = &(result.error);
|
|
(*value_67) = DeclarationError_ParameterListSyntax;
|
|
return result;
|
|
}
|
|
DeclarationError* value_68 = &(result.error);
|
|
(*value_68) = (DeclarationError)(declaration_ParameterListError(result.list, true, name_limit));
|
|
return result;
|
|
}
|
|
|
|
LibraryDeclaration
|
|
declaration_SystemLibrary(String source, int64_t name_limit, int64_t path_limit)
|
|
{
|
|
LibraryDeclaration result = {0};
|
|
String* value_0 = &(result.name);
|
|
(*value_0) = declaration_SymbolBeforeColons(source, name_limit);
|
|
if ((int64_t)(result.name).length == 0LL) {
|
|
return result;
|
|
}
|
|
String value_1 = source;
|
|
int64_t value_2 = (int64_t)((uint64_t)(declaration_Find(source, StringLiteral("::"))) + UINT64_C(2));
|
|
int64_t value_3 = source_text_SkipSpace(source, value_2, true);
|
|
String declaration = StringRangeAt(value_1, (int64_t)value_3, (int64_t)value_1.length);
|
|
bool value_4 = source_StartsWord(declaration, StringLiteral("#system_library"));
|
|
if (!value_4) {
|
|
return result;
|
|
}
|
|
bool* value_5 = &(result.present);
|
|
(*value_5) = true;
|
|
String value_6 = declaration;
|
|
int64_t value_7 = source_text_SkipSpace(declaration, 15LL, true);
|
|
String argument = StringRangeAt(value_6, (int64_t)value_7, (int64_t)value_6.length);
|
|
QuotedText value_8 = {0};
|
|
{
|
|
String value_10 = argument;
|
|
int64_t value_11 = path_limit;
|
|
int64_t value_12 = declaration_Find(value_10, StringLiteral("\""));
|
|
if (value_12 < 0LL) {
|
|
value_8 = (QuotedText){0};
|
|
goto value_9;
|
|
}
|
|
int64_t value_13 = declaration_Find(StringRangeAt(value_10, (int64_t)((int64_t)((uint64_t)value_12 + UINT64_C(1))), (int64_t)value_10.length), StringLiteral("\""));
|
|
if (value_13 < 0LL || value_13 >= value_11) {
|
|
value_8 = (QuotedText){0};
|
|
goto value_9;
|
|
}
|
|
value_13 = (int64_t)((uint64_t)value_13 + ((uint64_t)value_12 + UINT64_C(1)));
|
|
String value_14 = StringRangeAt(value_10, (int64_t)((int64_t)((uint64_t)value_12 + UINT64_C(1))), (int64_t)value_13);
|
|
value_8 = (QuotedText){.valid = true, .value = value_14, .end = (int64_t)((uint64_t)value_13 + UINT64_C(1))};
|
|
value_9: ;
|
|
}
|
|
QuotedText quoted = value_8;
|
|
if ((int64_t)(argument).length == 0LL || (uint8_t)argument.data[0] != 34 || !quoted.valid || (int64_t)(quoted.value).length == 0LL) {
|
|
DeclarationError* value_15 = &(result.error);
|
|
(*value_15) = DeclarationError_LibraryQuote;
|
|
return result;
|
|
}
|
|
String* value_16 = &(result.target);
|
|
(*value_16) = quoted.value;
|
|
String value_17 = argument;
|
|
int64_t value_18 = source_text_SkipSpace(argument, quoted.end, true);
|
|
if (!StringEqual(StringRangeAt(value_17, (int64_t)value_18, (int64_t)value_17.length), StringLiteral(";"))) {
|
|
DeclarationError* value_19 = &(result.error);
|
|
(*value_19) = DeclarationError_LibraryEnd;
|
|
return result;
|
|
}
|
|
{
|
|
String value_20 = result.target;
|
|
String loop_view_21 = StringRangeAt(value_20, (int64_t)0, (int64_t)value_20.length);
|
|
int64_t loop_count_21 = (int64_t)(loop_view_21).length;
|
|
int64_t loop_cursor_21 = 0LL;
|
|
while (loop_cursor_21 < loop_count_21) {
|
|
int64_t loop_index_21 = loop_cursor_21;
|
|
uint8_t byte = (uint8_t)loop_view_21.data[loop_index_21];
|
|
if (byte < 32 || byte == 34 || byte == 92) {
|
|
DeclarationError* value_21 = &(result.error);
|
|
(*value_21) = DeclarationError_LibraryCharacter;
|
|
return result;
|
|
}
|
|
loop_cursor_21 = (int64_t)((uint64_t)loop_cursor_21 + UINT64_C(1));
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
MethodSymbol
|
|
declaration_ForeignMethod(String source, int64_t receiver_limit, int64_t method_limit)
|
|
{
|
|
MethodSymbol result = {0};
|
|
int64_t dot = declaration_Find(source, StringLiteral("."));
|
|
if (dot <= 0LL) {
|
|
return result;
|
|
}
|
|
String* value_0 = &(result.receiver);
|
|
(*value_0) = StringRangeAt(source, (int64_t)0LL, (int64_t)dot);
|
|
String* value_1 = &(result.method);
|
|
(*value_1) = StringRangeAt(source, (int64_t)((int64_t)((uint64_t)dot + UINT64_C(1))), (int64_t)source.length);
|
|
if ((uint8_t)source.data[0] == 40) {
|
|
if ((int64_t)(result.receiver).length < 3LL || (uint8_t)result.receiver.data[((int64_t)((uint64_t)((int64_t)(result.receiver).length) - UINT64_C(1)))] != 41) {
|
|
return result;
|
|
}
|
|
String* value_2 = &(result.receiver);
|
|
String value_3 = result.receiver;
|
|
(*value_2) = StringRangeAt(value_3, (int64_t)1LL, (int64_t)((int64_t)((uint64_t)((int64_t)(result.receiver).length) - UINT64_C(1))));
|
|
}
|
|
if ((int64_t)(result.receiver).length >= receiver_limit || (int64_t)(result.method).length >= method_limit) {
|
|
return result;
|
|
}
|
|
String name = result.receiver;
|
|
if ((int64_t)(name).length > 0LL && (uint8_t)name.data[0] == 42) {
|
|
name = StringRangeAt(name, (int64_t)1LL, (int64_t)name.length);
|
|
}
|
|
bool* value_4 = &(result.valid);
|
|
bool value_5 = source_IdentifierText(name, false);
|
|
(*value_4) = value_5 && source_IdentifierText(result.method, false);
|
|
return result;
|
|
}
|
|
|
|
ForeignDeclaration
|
|
declaration_ParseForeign(String source, int64_t name_limit)
|
|
{
|
|
ForeignDeclaration result = {0};
|
|
String* value_0 = &(result.name);
|
|
String value_1 = declaration_SymbolBeforeColons(source, name_limit);
|
|
(*value_0) = value_1;
|
|
if ((int64_t)(result.name).length == 0LL) {
|
|
return result;
|
|
}
|
|
String value_2 = source;
|
|
int64_t value_3 = (int64_t)((uint64_t)(declaration_Find(source, StringLiteral("::"))) + UINT64_C(2));
|
|
int64_t value_4 = source_text_SkipSpace(source, value_3, true);
|
|
String declaration = StringRangeAt(value_2, (int64_t)value_4, (int64_t)value_2.length);
|
|
int32_t attributes[5] = {0};
|
|
bool after_foreign[5] = {0};
|
|
int64_t directive = -1LL;
|
|
bool body = false;
|
|
int64_t at = 0LL;
|
|
while (at < (int64_t)(declaration).length) {
|
|
Scan token = scan_NextToken(declaration, at, 1, 1);
|
|
if (((TokenKind)(token.kind)) == TokenKind_Eof) {
|
|
break;
|
|
}
|
|
String spelling = StringRangeAt(declaration, (int64_t)token.begin, (int64_t)token.end);
|
|
if (StringEqual(spelling, StringLiteral("/")) && token.end < (int64_t)(declaration).length && (uint8_t)declaration.data[token.end] == 47) {
|
|
break;
|
|
}
|
|
if (StringEqual(spelling, StringLiteral("{"))) {
|
|
body = true;
|
|
}
|
|
if (((TokenKind)(token.kind)) == TokenKind_Directive) {
|
|
if (StringEqual(spelling, StringLiteral("#foreign")) && directive < 0LL) {
|
|
directive = token.begin;
|
|
}
|
|
int64_t attribute = -1LL;
|
|
if (StringEqual(spelling, StringLiteral("#go_results"))) {
|
|
attribute = 0LL;
|
|
}
|
|
if (StringEqual(spelling, StringLiteral("#go_field"))) {
|
|
attribute = 1LL;
|
|
}
|
|
if (StringEqual(spelling, StringLiteral("#go_defer"))) {
|
|
attribute = 2LL;
|
|
}
|
|
if (StringEqual(spelling, StringLiteral("#go_variadic"))) {
|
|
attribute = 3LL;
|
|
}
|
|
if (StringEqual(spelling, StringLiteral("#reads"))) {
|
|
attribute = 4LL;
|
|
}
|
|
if (attribute >= 0LL) {
|
|
int32_t* value_5 = &(attributes[attribute]);
|
|
(*value_5) = (int32_t)((uint32_t)((*value_5)) + 1u);
|
|
if (directive >= 0LL) {
|
|
bool* value_6 = &(after_foreign[attribute]);
|
|
(*value_6) = true;
|
|
}
|
|
}
|
|
}
|
|
at = token.end;
|
|
}
|
|
if (directive < 0LL) {
|
|
return result;
|
|
}
|
|
bool* value_7 = &(result.present);
|
|
(*value_7) = true;
|
|
bool* value_8 = &(result.is_type);
|
|
bool value_9 = source_StartsWord(declaration, StringLiteral("#type"));
|
|
(*value_8) = value_9;
|
|
bool* value_10 = &(result.go_results);
|
|
(*value_10) = (attributes)[0] > 0;
|
|
bool* value_11 = &(result.go_field);
|
|
(*value_11) = (attributes)[1] > 0;
|
|
bool* value_12 = &(result.go_defer);
|
|
(*value_12) = (attributes)[2] > 0;
|
|
bool* value_13 = &(result.go_variadic);
|
|
(*value_13) = (attributes)[3] > 0;
|
|
bool* value_14 = &(result.reads);
|
|
(*value_14) = (attributes)[4] > 0;
|
|
if (result.go_results && (result.is_type || (attributes)[0] > 1 || (after_foreign)[0])) {
|
|
DeclarationError* value_15 = &(result.error);
|
|
(*value_15) = DeclarationError_ForeignResults;
|
|
return result;
|
|
}
|
|
if (result.go_field && (result.is_type || result.go_results || (attributes)[1] > 1 || (after_foreign)[1])) {
|
|
DeclarationError* value_16 = &(result.error);
|
|
(*value_16) = DeclarationError_ForeignField;
|
|
return result;
|
|
}
|
|
if (result.go_defer && (result.is_type || result.go_results || result.go_field || (attributes)[2] > 1 || (after_foreign)[2])) {
|
|
DeclarationError* value_17 = &(result.error);
|
|
(*value_17) = DeclarationError_ForeignDefer;
|
|
return result;
|
|
}
|
|
if (result.go_variadic && (result.is_type || result.go_field || (attributes)[3] > 1 || (after_foreign)[3])) {
|
|
DeclarationError* value_18 = &(result.error);
|
|
(*value_18) = DeclarationError_ForeignVariadic;
|
|
return result;
|
|
}
|
|
if (result.reads && (result.is_type || (attributes)[4] > 1 || (after_foreign)[4])) {
|
|
DeclarationError* value_19 = &(result.error);
|
|
(*value_19) = DeclarationError_ForeignReads;
|
|
return result;
|
|
}
|
|
bool value_20 = result.is_type;
|
|
bool value_21 = value_20;
|
|
if (value_21) {
|
|
int64_t value_22 = source_text_SkipSpace(declaration, 5LL, true);
|
|
value_21 = (value_22 != directive);
|
|
}
|
|
if (value_21) {
|
|
DeclarationError* value_23 = &(result.error);
|
|
(*value_23) = DeclarationError_ForeignType;
|
|
return result;
|
|
}
|
|
if (!result.is_type && ((int64_t)(declaration).length == 0LL || (uint8_t)declaration.data[0] != 40)) {
|
|
bool* value_24 = &(result.present);
|
|
(*value_24) = false;
|
|
return result;
|
|
}
|
|
if (body) {
|
|
DeclarationError* value_25 = &(result.error);
|
|
(*value_25) = DeclarationError_ForeignBody;
|
|
return result;
|
|
}
|
|
declaration_ParseForeignTail(declaration, directive, name_limit, &(result));
|
|
return result;
|
|
}
|
|
|
|
void
|
|
declaration_ParseForeignTail(String declaration, int64_t directive, int64_t name_limit, ForeignDeclaration* result)
|
|
{
|
|
int64_t at = source_text_SkipSpace(declaration, (int64_t)((uint64_t)directive + UINT64_C(8)), true);
|
|
int64_t begin = at;
|
|
while (at < (int64_t)(declaration).length && source_text_IdentifierByte((uint8_t)declaration.data[at])) {
|
|
at = (int64_t)((uint64_t)at + UINT64_C(1));
|
|
}
|
|
String* value_0 = &(result->library);
|
|
(*value_0) = StringRangeAt(declaration, (int64_t)begin, (int64_t)at);
|
|
int64_t value_1 = (int64_t)(result->library).length;
|
|
bool value_2 = value_1 >= name_limit;
|
|
bool value_3 = value_2;
|
|
if (!value_3) {
|
|
bool value_4 = source_IdentifierText(result->library, false);
|
|
value_3 = !value_4;
|
|
}
|
|
if (value_3) {
|
|
DeclarationError* value_5 = &(result->error);
|
|
(*value_5) = DeclarationError_ForeignLibrary;
|
|
return;
|
|
}
|
|
at = source_text_SkipSpace(declaration, at, true);
|
|
String* value_6 = &(result->symbol);
|
|
(*value_6) = result->name;
|
|
if (at < (int64_t)(declaration).length && (uint8_t)declaration.data[at] == 34) {
|
|
QuotedText quoted = declaration_UsingQuoted(StringRangeAt(declaration, (int64_t)at, (int64_t)declaration.length), name_limit);
|
|
if (!quoted.valid) {
|
|
DeclarationError* value_7 = &(result->error);
|
|
(*value_7) = DeclarationError_ForeignSymbol;
|
|
return;
|
|
}
|
|
String* value_8 = &(result->symbol);
|
|
(*value_8) = quoted.value;
|
|
at = source_text_SkipSpace(declaration, (int64_t)((uint64_t)at + (uint64_t)(quoted.end)), true);
|
|
}
|
|
String value_9 = StringRangeAt(declaration, (int64_t)at, (int64_t)declaration.length);
|
|
String value_10 = StringView(NULL, 0);
|
|
{
|
|
String value_12 = value_9;
|
|
SourceRange value_13 = source_text_TrimRange(value_12);
|
|
value_10 = StringRangeAt(value_12, (int64_t)value_13.begin, (int64_t)value_13.end);
|
|
}
|
|
if (!StringEqual(value_10, StringLiteral(";"))) {
|
|
DeclarationError* value_14 = &(result->error);
|
|
(*value_14) = DeclarationError_ForeignEnd;
|
|
}
|
|
}
|
|
|
|
ForeignData
|
|
declaration_ParseForeignData(String source, int64_t name_limit)
|
|
{
|
|
ForeignData result = {0};
|
|
int64_t begin = source_text_SkipSpace(source, 0LL, true);
|
|
int64_t end = begin;
|
|
while (end < (int64_t)(source).length && source_text_IdentifierByte((uint8_t)source.data[end])) {
|
|
end = (int64_t)((uint64_t)end + UINT64_C(1));
|
|
}
|
|
int64_t colon = source_text_SkipSpace(source, end, true);
|
|
if (end == begin || colon >= (int64_t)(source).length || (uint8_t)source.data[colon] != 58) {
|
|
return result;
|
|
}
|
|
if ((int64_t)((uint64_t)colon + UINT64_C(1)) < (int64_t)(source).length && ((uint8_t)source.data[((int64_t)((uint64_t)colon + UINT64_C(1)))] == 58 || (uint8_t)source.data[((int64_t)((uint64_t)colon + UINT64_C(1)))] == 61)) {
|
|
return result;
|
|
}
|
|
int64_t directive = -1LL;
|
|
bool value = false;
|
|
int64_t at = (int64_t)((uint64_t)colon + UINT64_C(1));
|
|
while (at < (int64_t)(source).length) {
|
|
Scan token = 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 (((TokenKind)(token.kind)) == TokenKind_Directive) {
|
|
if (StringEqual(spelling, StringLiteral("#foreign")) && directive < 0LL) {
|
|
directive = token.begin;
|
|
} else {
|
|
value = true;
|
|
}
|
|
}
|
|
if (StringEqual(spelling, StringLiteral("=")) || StringEqual(spelling, StringLiteral("{"))) {
|
|
value = true;
|
|
}
|
|
at = token.end;
|
|
}
|
|
if (directive < 0LL) {
|
|
return result;
|
|
}
|
|
bool* value_0 = &(result.declaration.present);
|
|
(*value_0) = true;
|
|
String* value_1 = &(result.declaration.name);
|
|
(*value_1) = StringRangeAt(source, (int64_t)begin, (int64_t)end);
|
|
if ((int64_t)((uint64_t)end - (uint64_t)begin) >= name_limit) {
|
|
DeclarationError* value_2 = &(result.declaration.error);
|
|
(*value_2) = DeclarationError_ForeignDataType;
|
|
return result;
|
|
}
|
|
if (value) {
|
|
DeclarationError* value_3 = &(result.declaration.error);
|
|
(*value_3) = DeclarationError_ForeignDataValue;
|
|
return result;
|
|
}
|
|
String* value_4 = &(result.type);
|
|
String value_5 = StringRangeAt(source, (int64_t)((int64_t)((uint64_t)colon + UINT64_C(1))), (int64_t)directive);
|
|
String value_6 = StringView(NULL, 0);
|
|
{
|
|
String value_8 = value_5;
|
|
SourceRange value_9 = source_text_TrimRange(value_8);
|
|
value_6 = StringRangeAt(value_8, (int64_t)value_9.begin, (int64_t)value_9.end);
|
|
}
|
|
(*value_4) = value_6;
|
|
if ((int64_t)(result.type).length == 0LL) {
|
|
DeclarationError* value_10 = &(result.declaration.error);
|
|
(*value_10) = DeclarationError_ForeignDataType;
|
|
return result;
|
|
}
|
|
declaration_ParseForeignTail(source, directive, name_limit, &(result.declaration));
|
|
return result;
|
|
}
|
|
|
|
ForeignTarget
|
|
declaration_ResolveForeignTarget(ForeignDeclaration declaration, String library, Slice output, int64_t name_limit)
|
|
{
|
|
ForeignTarget result = {0};
|
|
DeclarationError* value_0 = &(result.error);
|
|
(*value_0) = (DeclarationError)(declaration.error);
|
|
if (((DeclarationError)(result.error)) != DeclarationError_None || !declaration.present) {
|
|
return result;
|
|
}
|
|
bool go = (int64_t)(library).length >= 3LL && StringEqual(StringRangeAt(library, (int64_t)0LL, (int64_t)3LL), StringLiteral("go:"));
|
|
MethodSymbol method = {0};
|
|
if (!declaration.is_type && go) {
|
|
method = declaration_ForeignMethod(declaration.symbol, name_limit, name_limit);
|
|
}
|
|
bool value_1 = source_IdentifierText(declaration.symbol, false);
|
|
if (!value_1 && !method.valid) {
|
|
DeclarationError* value_2 = &(result.error);
|
|
(*value_2) = DeclarationError_ForeignSymbol;
|
|
return result;
|
|
}
|
|
if (StringEqual(library, StringLiteral("host_api"))) {
|
|
if (!StringEqual(declaration.symbol, declaration.name)) {
|
|
DeclarationError* value_3 = &(result.error);
|
|
(*value_3) = DeclarationError_ForeignHostRename;
|
|
}
|
|
} else if (method.valid) {
|
|
declaration_Put(output, &(result.count), library);
|
|
declaration_Put(output, &(result.count), StringLiteral(".("));
|
|
declaration_Put(output, &(result.count), method.receiver);
|
|
declaration_Put(output, &(result.count), StringLiteral(")."));
|
|
declaration_Put(output, &(result.count), method.method);
|
|
} else if (go) {
|
|
declaration_Put(output, &(result.count), library);
|
|
declaration_Put(output, &(result.count), StringLiteral("."));
|
|
declaration_Put(output, &(result.count), declaration.symbol);
|
|
} else {
|
|
declaration_Put(output, &(result.count), StringLiteral("c."));
|
|
declaration_Put(output, &(result.count), declaration.symbol);
|
|
}
|
|
if (((DeclarationError)(result.error)) != DeclarationError_None) {
|
|
return result;
|
|
}
|
|
if (declaration.go_results && !go) {
|
|
DeclarationError* value_4 = &(result.error);
|
|
(*value_4) = DeclarationError_ForeignGoResults;
|
|
} else if (declaration.go_field && !go) {
|
|
DeclarationError* value_5 = &(result.error);
|
|
(*value_5) = DeclarationError_ForeignGoField;
|
|
} else if (declaration.go_defer && !go) {
|
|
DeclarationError* value_6 = &(result.error);
|
|
(*value_6) = DeclarationError_ForeignGoDefer;
|
|
} else if (declaration.go_variadic && !go) {
|
|
DeclarationError* value_7 = &(result.error);
|
|
(*value_7) = DeclarationError_ForeignGoVariadic;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
bool
|
|
declaration_ForeignVarargs(String parameters)
|
|
{
|
|
String value_0 = StringView(NULL, 0);
|
|
{
|
|
String value_2 = parameters;
|
|
SourceRange value_3 = source_text_TrimRange(value_2);
|
|
value_0 = StringRangeAt(value_2, (int64_t)value_3.begin, (int64_t)value_3.end);
|
|
}
|
|
int64_t value_4 = (int64_t)(value_0).length;
|
|
if (value_4 == 0LL) {
|
|
return false;
|
|
}
|
|
int64_t at = 0LL;
|
|
String last = StringLiteral("");
|
|
while (at >= 0LL) {
|
|
SourcePart range = source_text_NextSourcePart(parameters, at);
|
|
String value_5 = StringRangeAt(parameters, (int64_t)range.begin, (int64_t)range.end);
|
|
String value_6 = StringView(NULL, 0);
|
|
{
|
|
String value_8 = value_5;
|
|
SourceRange value_9 = source_text_TrimRange(value_8);
|
|
value_6 = StringRangeAt(value_8, (int64_t)value_9.begin, (int64_t)value_9.end);
|
|
}
|
|
last = value_6;
|
|
at = range.next;
|
|
}
|
|
int64_t colon = declaration_Find(last, StringLiteral(":"));
|
|
if (colon >= 0LL) {
|
|
String value_10 = StringRangeAt(last, (int64_t)((int64_t)((uint64_t)colon + UINT64_C(1))), (int64_t)last.length);
|
|
String value_11 = StringView(NULL, 0);
|
|
{
|
|
String value_13 = value_10;
|
|
SourceRange value_14 = source_text_TrimRange(value_13);
|
|
value_11 = StringRangeAt(value_13, (int64_t)value_14.begin, (int64_t)value_14.end);
|
|
}
|
|
last = value_11;
|
|
}
|
|
return StringEqual(last, StringLiteral("..any"));
|
|
}
|
|
|
|
ResultDeclaration
|
|
declaration_ParseResults(String source, String template_parameters)
|
|
{
|
|
ResultDeclaration result = {0};
|
|
String value_0 = source;
|
|
String value_1 = StringView(NULL, 0);
|
|
{
|
|
String value_3 = value_0;
|
|
SourceRange value_4 = source_text_TrimRange(value_3);
|
|
value_1 = StringRangeAt(value_3, (int64_t)value_4.begin, (int64_t)value_4.end);
|
|
}
|
|
String list = value_1;
|
|
bool value_5 = (int64_t)(list).length > 1LL && (uint8_t)list.data[0] == 40;
|
|
bool value_6 = value_5;
|
|
if (value_6) {
|
|
int64_t value_7 = source_ClosingParenthesis(list);
|
|
int64_t value_8 = (int64_t)((uint64_t)((int64_t)(list).length) - UINT64_C(1));
|
|
value_6 = (value_7 == value_8);
|
|
}
|
|
bool value_9 = value_6;
|
|
bool value_10 = value_9;
|
|
if (value_10) {
|
|
int64_t value_11 = declaration_Find(list, StringLiteral(":"));
|
|
value_10 = (value_11 >= 0LL);
|
|
}
|
|
bool named = value_10;
|
|
if (named) {
|
|
list = StringRangeAt(list, (int64_t)1LL, (int64_t)((int64_t)((uint64_t)((int64_t)(list).length) - UINT64_C(1))));
|
|
}
|
|
int64_t at = 0LL;
|
|
while (at >= 0LL) {
|
|
if (result.count == 16) {
|
|
DeclarationError* value_12 = &(result.error);
|
|
(*value_12) = DeclarationError_ResultCount;
|
|
return result;
|
|
}
|
|
SourcePart range = source_text_NextSourcePart(list, at);
|
|
String* value_13 = &(result.types[result.count]);
|
|
String value_14 = StringRangeAt(list, (int64_t)range.begin, (int64_t)range.end);
|
|
String value_15 = StringView(NULL, 0);
|
|
{
|
|
String value_17 = value_14;
|
|
SourceRange value_18 = source_text_TrimRange(value_17);
|
|
value_15 = StringRangeAt(value_17, (int64_t)value_18.begin, (int64_t)value_18.end);
|
|
}
|
|
(*value_13) = value_15;
|
|
int32_t* value_19 = &(result.count);
|
|
(*value_19) = (int32_t)((uint32_t)((*value_19)) + 1u);
|
|
at = range.next;
|
|
}
|
|
if (result.count < 2) {
|
|
int32_t* value_20 = &(result.count);
|
|
(*value_20) = 0;
|
|
return result;
|
|
}
|
|
{
|
|
int32_t range_first_21 = 0;
|
|
int32_t range_last_21 = (int32_t)((uint32_t)(result.count) - 1u);
|
|
int32_t index = range_first_21;
|
|
if (index <= range_last_21) for (;;) {
|
|
String part = (result.types)[index];
|
|
if (named) {
|
|
int64_t colon = declaration_Find(part, StringLiteral(":"));
|
|
bool value_21 = colon < 0LL;
|
|
if (!value_21) {
|
|
String value_22 = StringRangeAt(part, (int64_t)0LL, (int64_t)colon);
|
|
String value_23 = StringView(NULL, 0);
|
|
{
|
|
String value_25 = value_22;
|
|
SourceRange value_26 = source_text_TrimRange(value_25);
|
|
value_23 = StringRangeAt(value_25, (int64_t)value_26.begin, (int64_t)value_26.end);
|
|
}
|
|
bool value_27 = source_IdentifierText(value_23, false);
|
|
value_21 = !value_27;
|
|
}
|
|
if (value_21) {
|
|
DeclarationError* value_28 = &(result.error);
|
|
(*value_28) = DeclarationError_ResultName;
|
|
return result;
|
|
}
|
|
String value_29 = StringRangeAt(part, (int64_t)((int64_t)((uint64_t)colon + UINT64_C(1))), (int64_t)part.length);
|
|
String value_30 = StringView(NULL, 0);
|
|
{
|
|
String value_32 = value_29;
|
|
SourceRange value_33 = source_text_TrimRange(value_32);
|
|
value_30 = StringRangeAt(value_32, (int64_t)value_33.begin, (int64_t)value_33.end);
|
|
}
|
|
part = value_30;
|
|
String* value_34 = &(result.types[index]);
|
|
(*value_34) = part;
|
|
}
|
|
bool value_35 = (int64_t)(part).length == 0LL;
|
|
if (!value_35) {
|
|
int64_t value_36 = declaration_Find(part, StringLiteral("$"));
|
|
value_35 = (value_36 >= 0LL);
|
|
}
|
|
bool value_37 = value_35;
|
|
if (!value_37) {
|
|
int64_t value_38 = declaration_Find(part, StringLiteral("\000"));
|
|
value_37 = (value_38 >= 0LL);
|
|
}
|
|
if (value_37) {
|
|
DeclarationError* value_39 = &(result.error);
|
|
(*value_39) = DeclarationError_ResultType;
|
|
return result;
|
|
}
|
|
int64_t cursor = 0LL;
|
|
while (cursor < (int64_t)(part).length) {
|
|
bool value_40 = source_IdentifierText(StringRangeAt(part, (int64_t)cursor, (int64_t)((int64_t)((uint64_t)cursor + UINT64_C(1)))), false);
|
|
if (!value_40) {
|
|
cursor = (int64_t)((uint64_t)cursor + UINT64_C(1));
|
|
continue;
|
|
}
|
|
int64_t begin = cursor;
|
|
cursor = (int64_t)((uint64_t)cursor + UINT64_C(1));
|
|
while (cursor < (int64_t)(part).length && source_text_IdentifierByte((uint8_t)part.data[cursor])) {
|
|
cursor = (int64_t)((uint64_t)cursor + UINT64_C(1));
|
|
}
|
|
String parameter = StringRangeAt(part, (int64_t)begin, (int64_t)cursor);
|
|
bool value_41 = declaration_ParameterIn(template_parameters, parameter);
|
|
if (!value_41) {
|
|
continue;
|
|
}
|
|
bool seen = false;
|
|
{
|
|
int32_t range_first_52 = 0;
|
|
int32_t range_last_52 = (int32_t)((uint32_t)(result.parameter_count) - 1u);
|
|
int32_t previous = range_first_52;
|
|
if (previous <= range_last_52) for (;;) {
|
|
if (StringEqual((result.parameters)[previous], parameter)) {
|
|
seen = true;
|
|
}
|
|
if (previous == range_last_52) {
|
|
break;
|
|
}
|
|
previous = (int32_t)((uint32_t)previous + 1u);
|
|
}
|
|
}
|
|
if (seen) {
|
|
continue;
|
|
}
|
|
if (result.parameter_count == 64) {
|
|
DeclarationError* value_42 = &(result.error);
|
|
(*value_42) = DeclarationError_ResultParameters;
|
|
return result;
|
|
}
|
|
String* value_43 = &(result.parameters[result.parameter_count]);
|
|
(*value_43) = parameter;
|
|
int32_t* value_44 = &(result.parameter_count);
|
|
(*value_44) = (int32_t)((uint32_t)((*value_44)) + 1u);
|
|
}
|
|
if (index == range_last_21) {
|
|
break;
|
|
}
|
|
index = (int32_t)((uint32_t)index + 1u);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
int64_t
|
|
declaration_ResultsRecord(ResultDeclaration results, Slice output)
|
|
{
|
|
int64_t used = 0LL;
|
|
declaration_Put(output, &(used), StringLiteral("Results"));
|
|
{
|
|
int32_t range_first_2 = 0;
|
|
int32_t range_last_2 = (int32_t)((uint32_t)(results.count) - 1u);
|
|
int32_t index = range_first_2;
|
|
if (index <= range_last_2) for (;;) {
|
|
declaration_Put(output, &(used), StringLiteral("__"));
|
|
{
|
|
String value_0 = (results.types)[index];
|
|
String loop_view_4 = StringRangeAt(value_0, (int64_t)0, (int64_t)value_0.length);
|
|
int64_t loop_count_4 = (int64_t)(loop_view_4).length;
|
|
int64_t loop_cursor_4 = 0LL;
|
|
while (loop_cursor_4 < loop_count_4) {
|
|
int64_t loop_index_4 = loop_cursor_4;
|
|
uint8_t byte = (uint8_t)loop_view_4.data[loop_index_4];
|
|
if (source_text_SpaceByte(byte)) {
|
|
loop_cursor_4 = (int64_t)((uint64_t)loop_cursor_4 + UINT64_C(1));
|
|
continue;
|
|
}
|
|
uint8_t normalized = byte;
|
|
bool value_1 = source_text_IdentifierByte(byte);
|
|
if (!value_1) {
|
|
normalized = 95;
|
|
if (byte == 42) {
|
|
normalized = 112;
|
|
} else if (byte == 91) {
|
|
normalized = 97;
|
|
}
|
|
}
|
|
declaration_PutByte(output, &(used), normalized);
|
|
loop_cursor_4 = (int64_t)((uint64_t)loop_cursor_4 + UINT64_C(1));
|
|
}
|
|
}
|
|
if (index == range_last_2) {
|
|
break;
|
|
}
|
|
index = (int32_t)((uint32_t)index + 1u);
|
|
}
|
|
}
|
|
return used;
|
|
}
|
|
|
|
int64_t
|
|
declaration_ResultsParameters(ResultDeclaration results, Slice output)
|
|
{
|
|
int64_t used = 0LL;
|
|
{
|
|
int32_t range_first_1 = 0;
|
|
int32_t range_last_1 = (int32_t)((uint32_t)(results.parameter_count) - 1u);
|
|
int32_t index = range_first_1;
|
|
if (index <= range_last_1) for (;;) {
|
|
if (index > 0) {
|
|
declaration_Put(output, &(used), StringLiteral(","));
|
|
}
|
|
declaration_Put(output, &(used), (results.parameters)[index]);
|
|
if (index == range_last_1) {
|
|
break;
|
|
}
|
|
index = (int32_t)((uint32_t)index + 1u);
|
|
}
|
|
}
|
|
return used;
|
|
}
|
|
|
|
int64_t
|
|
declaration_ResultsBody(ResultDeclaration results, Slice output)
|
|
{
|
|
int64_t used = 0LL;
|
|
{
|
|
int32_t range_first_1 = 0;
|
|
int32_t range_last_1 = (int32_t)((uint32_t)(results.count) - 1u);
|
|
int32_t index = range_first_1;
|
|
if (index <= range_last_1) for (;;) {
|
|
declaration_Put(output, &(used), StringLiteral("value_"));
|
|
if (index >= 10) {
|
|
declaration_Put(output, &(used), StringLiteral("1"));
|
|
}
|
|
declaration_PutByte(output, &(used), (uint8_t)(((int32_t)(48u + (uint32_t)((index % 10))))));
|
|
declaration_Put(output, &(used), StringLiteral(": "));
|
|
declaration_Put(output, &(used), (results.types)[index]);
|
|
declaration_Put(output, &(used), StringLiteral("\n"));
|
|
if (index == range_last_1) {
|
|
break;
|
|
}
|
|
index = (int32_t)((uint32_t)index + 1u);
|
|
}
|
|
}
|
|
return used;
|
|
}
|
|
|
|
ResultReturn
|
|
declaration_RewriteResultReturn(String source, String record, int32_t results, Slice output)
|
|
{
|
|
ResultReturn result = {0};
|
|
String value_0 = source;
|
|
String value_1 = StringView(NULL, 0);
|
|
{
|
|
String value_3 = value_0;
|
|
SourceRange value_4 = source_text_TrimRange(value_3);
|
|
value_1 = StringRangeAt(value_3, (int64_t)value_4.begin, (int64_t)value_4.end);
|
|
}
|
|
String body = value_1;
|
|
bool value_5 = source_StartsWord(body, StringLiteral("return"));
|
|
if (!value_5) {
|
|
return result;
|
|
}
|
|
String value = declaration_StatementValue(StringRangeAt(body, (int64_t)6LL, (int64_t)body.length));
|
|
int64_t at = 0LL;
|
|
while (at >= 0LL) {
|
|
SourcePart range = source_text_NextSourcePart(value, at);
|
|
int32_t* value_6 = &(result.values);
|
|
(*value_6) = (int32_t)((uint32_t)((*value_6)) + 1u);
|
|
at = range.next;
|
|
}
|
|
if (result.values < 2) {
|
|
return result;
|
|
}
|
|
bool* value_7 = &(result.present);
|
|
(*value_7) = true;
|
|
if (result.values != results) {
|
|
DeclarationError* value_8 = &(result.error);
|
|
(*value_8) = DeclarationError_ReturnCount;
|
|
return result;
|
|
}
|
|
declaration_Put(output, &(result.count), StringLiteral("return "));
|
|
declaration_Put(output, &(result.count), record);
|
|
declaration_Put(output, &(result.count), StringLiteral(".{"));
|
|
declaration_Put(output, &(result.count), value);
|
|
declaration_Put(output, &(result.count), StringLiteral("};"));
|
|
return result;
|
|
}
|
|
|
|
ResultBinding
|
|
declaration_MultipleBinding(String source, int32_t maximum, int64_t name_limit)
|
|
{
|
|
ResultBinding result = {0};
|
|
int64_t at = source_text_SkipSpace(source, 0LL, true);
|
|
while (at < (int64_t)(source).length) {
|
|
int64_t begin = at;
|
|
while (at < (int64_t)(source).length && source_text_IdentifierByte((uint8_t)source.data[at])) {
|
|
at = (int64_t)((uint64_t)at + UINT64_C(1));
|
|
}
|
|
String name = StringRangeAt(source, (int64_t)begin, (int64_t)at);
|
|
bool value_0 = (int64_t)(name).length >= name_limit;
|
|
if (!value_0) {
|
|
bool value_1 = source_IdentifierText(name, false);
|
|
value_0 = !value_1;
|
|
}
|
|
if (value_0 || result.count == 16 || result.count >= maximum) {
|
|
return (ResultBinding){0};
|
|
}
|
|
String* value_2 = &(result.targets[result.count]);
|
|
(*value_2) = name;
|
|
int32_t* value_3 = &(result.count);
|
|
(*value_3) = (int32_t)((uint32_t)((*value_3)) + 1u);
|
|
at = source_text_SkipSpace(source, at, true);
|
|
if (at >= (int64_t)(source).length || (uint8_t)source.data[at] != 44) {
|
|
break;
|
|
}
|
|
at = source_text_SkipSpace(source, (int64_t)((uint64_t)at + UINT64_C(1)), true);
|
|
}
|
|
if (result.count < 2 || at >= (int64_t)(source).length) {
|
|
return (ResultBinding){0};
|
|
}
|
|
bool value_4 = (uint8_t)source.data[at] == 58 && (int64_t)((uint64_t)at + UINT64_C(1)) < (int64_t)(source).length;
|
|
if (value_4 && (uint8_t)source.data[((int64_t)((uint64_t)at + UINT64_C(1)))] == 61) {
|
|
bool* value_5 = &(result.inferred);
|
|
(*value_5) = true;
|
|
at = (int64_t)((uint64_t)at + UINT64_C(2));
|
|
} else if ((uint8_t)source.data[at] == 61 && ((int64_t)((uint64_t)at + UINT64_C(1)) == (int64_t)(source).length || (uint8_t)source.data[((int64_t)((uint64_t)at + UINT64_C(1)))] != 61)) {
|
|
at = (int64_t)((uint64_t)at + UINT64_C(1));
|
|
} else {
|
|
return (ResultBinding){0};
|
|
}
|
|
String* value_6 = &(result.value);
|
|
(*value_6) = declaration_StatementValue(StringRangeAt(source, (int64_t)at, (int64_t)source.length));
|
|
if ((int64_t)(result.value).length == 0LL) {
|
|
return (ResultBinding){0};
|
|
}
|
|
bool* value_7 = &(result.present);
|
|
(*value_7) = true;
|
|
return result;
|
|
}
|
|
|
|
static bool
|
|
declaration_ParameterIn(String source, String parameter)
|
|
{
|
|
int64_t at = 0LL;
|
|
while (at >= 0LL) {
|
|
SourcePart range = source_text_NextSourcePart(source, at);
|
|
String value_0 = StringRangeAt(source, (int64_t)range.begin, (int64_t)range.end);
|
|
String value_1 = StringView(NULL, 0);
|
|
{
|
|
String value_3 = value_0;
|
|
SourceRange value_4 = source_text_TrimRange(value_3);
|
|
value_1 = StringRangeAt(value_3, (int64_t)value_4.begin, (int64_t)value_4.end);
|
|
}
|
|
if (StringEqual(value_1, parameter)) {
|
|
return true;
|
|
}
|
|
at = range.next;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
static String
|
|
declaration_StatementValue(String source)
|
|
{
|
|
String value_0 = source;
|
|
String value_1 = StringView(NULL, 0);
|
|
{
|
|
String value_3 = value_0;
|
|
SourceRange value_4 = source_text_TrimRange(value_3);
|
|
value_1 = StringRangeAt(value_3, (int64_t)value_4.begin, (int64_t)value_4.end);
|
|
}
|
|
String value = value_1;
|
|
while ((int64_t)(value).length > 0LL && (uint8_t)value.data[((int64_t)((uint64_t)((int64_t)(value).length) - UINT64_C(1)))] == 59) {
|
|
String value_5 = StringRangeAt(value, (int64_t)0LL, (int64_t)((int64_t)((uint64_t)((int64_t)(value).length) - UINT64_C(1))));
|
|
String value_6 = StringView(NULL, 0);
|
|
{
|
|
String value_8 = value_5;
|
|
SourceRange value_9 = source_text_TrimRange(value_8);
|
|
value_6 = StringRangeAt(value_8, (int64_t)value_9.begin, (int64_t)value_9.end);
|
|
}
|
|
value = value_6;
|
|
}
|
|
return value;
|
|
}
|
|
|
|
static void
|
|
declaration_PutByte(Slice output, int64_t* used, uint8_t byte)
|
|
{
|
|
int64_t value_0 = *(used);
|
|
int64_t value_1 = (int64_t)(output).length;
|
|
if (value_0 < value_1) {
|
|
uint8_t* value_2 = &(((uint8_t *)(output).data)[*(used)]);
|
|
(*value_2) = byte;
|
|
}
|
|
int64_t* value_3 = &((*(used)));
|
|
(*value_3) = (int64_t)((uint64_t)((*value_3)) + UINT64_C(1));
|
|
}
|
|
|
|
static int64_t
|
|
declaration_AfterComment(String source, int64_t at)
|
|
{
|
|
if ((int64_t)((uint64_t)at + UINT64_C(1)) >= (int64_t)(source).length || (uint8_t)source.data[at] != 47) {
|
|
return at;
|
|
}
|
|
if ((uint8_t)source.data[((int64_t)((uint64_t)at + UINT64_C(1)))] == 47) {
|
|
return (int64_t)(source).length;
|
|
}
|
|
if ((uint8_t)source.data[((int64_t)((uint64_t)at + UINT64_C(1)))] != 42) {
|
|
return at;
|
|
}
|
|
at = (int64_t)((uint64_t)at + UINT64_C(2));
|
|
int32_t depth = 1;
|
|
while (at < (int64_t)(source).length && depth > 0) {
|
|
bool value_0 = (int64_t)((uint64_t)at + UINT64_C(1)) < (int64_t)(source).length && (uint8_t)source.data[at] == 47;
|
|
if (value_0 && (uint8_t)source.data[((int64_t)((uint64_t)at + UINT64_C(1)))] == 42) {
|
|
depth = (int32_t)((uint32_t)depth + 1u);
|
|
at = (int64_t)((uint64_t)at + UINT64_C(2));
|
|
} else {
|
|
bool value_1 = (int64_t)((uint64_t)at + UINT64_C(1)) < (int64_t)(source).length && (uint8_t)source.data[at] == 42;
|
|
if (value_1 && (uint8_t)source.data[((int64_t)((uint64_t)at + UINT64_C(1)))] == 47) {
|
|
depth = (int32_t)((uint32_t)depth - 1u);
|
|
at = (int64_t)((uint64_t)at + UINT64_C(2));
|
|
} else {
|
|
at = (int64_t)((uint64_t)at + UINT64_C(1));
|
|
}
|
|
}
|
|
}
|
|
return at;
|
|
}
|
|
|
|
bool
|
|
declaration_UsesTypeParameter(String source, String parameters)
|
|
{
|
|
String previous = StringLiteral("");
|
|
int64_t at = 0LL;
|
|
while (at < (int64_t)(source).length) {
|
|
Scan token = scan_NextToken(source, at, 1, 1);
|
|
if (((TokenKind)(token.kind)) == TokenKind_Eof) {
|
|
break;
|
|
}
|
|
int64_t comment = declaration_AfterComment(source, token.begin);
|
|
if (comment != token.begin) {
|
|
at = comment;
|
|
continue;
|
|
}
|
|
at = token.end;
|
|
String spelling = StringRangeAt(source, (int64_t)token.begin, (int64_t)token.end);
|
|
if (((TokenKind)(token.kind)) == TokenKind_Ident && !StringEqual(previous, StringLiteral("."))) {
|
|
Scan following = scan_NextToken(source, at, 1, 1);
|
|
bool label = (StringEqual(previous, StringLiteral("{")) || StringEqual(previous, StringLiteral(","))) && StringEqual(StringRangeAt(source, (int64_t)following.begin, (int64_t)following.end), StringLiteral("="));
|
|
int64_t parameter_at = 0LL;
|
|
while (!label && parameter_at < (int64_t)(parameters).length) {
|
|
SourcePart part = source_text_NextSourcePart(parameters, parameter_at);
|
|
String value_0 = StringRangeAt(parameters, (int64_t)part.begin, (int64_t)part.end);
|
|
String value_1 = StringView(NULL, 0);
|
|
{
|
|
String value_3 = value_0;
|
|
SourceRange value_4 = source_text_TrimRange(value_3);
|
|
value_1 = StringRangeAt(value_3, (int64_t)value_4.begin, (int64_t)value_4.end);
|
|
}
|
|
String name = value_1;
|
|
if ((int64_t)(name).length > 0LL && (uint8_t)name.data[0] == 36) {
|
|
name = StringRangeAt(name, (int64_t)1LL, (int64_t)name.length);
|
|
}
|
|
if (StringEqual(name, spelling)) {
|
|
return true;
|
|
}
|
|
if (part.next < 0LL) {
|
|
break;
|
|
}
|
|
parameter_at = part.next;
|
|
}
|
|
}
|
|
previous = spelling;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool
|
|
declaration_DefaultScopeIndependent(String source, int64_t token_limit)
|
|
{
|
|
String previous = StringLiteral("");
|
|
int64_t at = 0LL;
|
|
while (at < (int64_t)(source).length) {
|
|
Scan token = scan_NextToken(source, at, 1, 1);
|
|
if (((TokenKind)(token.kind)) == TokenKind_Eof) {
|
|
return true;
|
|
}
|
|
String spelling = StringRangeAt(source, (int64_t)token.begin, (int64_t)token.end);
|
|
if (((TokenKind)(token.kind)) == TokenKind_Unknown || (int64_t)(spelling).length >= token_limit) {
|
|
return false;
|
|
}
|
|
if (((TokenKind)(token.kind)) == TokenKind_Directive && !StringEqual(spelling, StringLiteral("#char"))) {
|
|
return false;
|
|
}
|
|
bool value_0 = ((TokenKind)(token.kind)) == TokenKind_Ident && !StringEqual(spelling, StringLiteral("true")) && !StringEqual(spelling, StringLiteral("false"));
|
|
if (value_0 && !StringEqual(spelling, StringLiteral("null"))) {
|
|
Scan next = scan_NextToken(source, token.end, 1, 1);
|
|
if ((!StringEqual(previous, StringLiteral("{")) && !StringEqual(previous, StringLiteral(","))) || !StringEqual(StringRangeAt(source, (int64_t)next.begin, (int64_t)next.end), StringLiteral("="))) {
|
|
return false;
|
|
}
|
|
}
|
|
previous = spelling;
|
|
at = token.end;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
TextRewrite
|
|
declaration_RewriteProcedureName(String source, String name, Slice output)
|
|
{
|
|
TextRewrite result = {0};
|
|
int64_t copied = 0LL;
|
|
int64_t at = 0LL;
|
|
while (at < (int64_t)(source).length) {
|
|
Scan token = scan_NextToken(source, at, 1, 1);
|
|
if (((TokenKind)(token.kind)) == TokenKind_Eof) {
|
|
break;
|
|
}
|
|
int64_t comment = declaration_AfterComment(source, token.begin);
|
|
if (comment != token.begin) {
|
|
at = comment;
|
|
continue;
|
|
}
|
|
at = token.end;
|
|
if (((TokenKind)(token.kind)) != TokenKind_Directive || !StringEqual(StringRangeAt(source, (int64_t)token.begin, (int64_t)token.end), StringLiteral("#procedure_name"))) {
|
|
continue;
|
|
}
|
|
Scan opening = scan_NextToken(source, at, 1, 1);
|
|
Scan closing = scan_NextToken(source, opening.end, 1, 1);
|
|
bool value_0 = !StringEqual(StringRangeAt(source, (int64_t)opening.begin, (int64_t)opening.end), StringLiteral("("));
|
|
if ((value_0 || (!StringEqual(StringRangeAt(source, (int64_t)closing.begin, (int64_t)closing.end), StringLiteral(")"))))) {
|
|
DeclarationError* value_1 = &(result.error);
|
|
(*value_1) = DeclarationError_ProcedureNameArguments;
|
|
return result;
|
|
}
|
|
declaration_Put(output, &(result.count), StringRangeAt(source, (int64_t)copied, (int64_t)token.begin));
|
|
declaration_Put(output, &(result.count), StringLiteral("\""));
|
|
declaration_Put(output, &(result.count), name);
|
|
declaration_Put(output, &(result.count), StringLiteral("\""));
|
|
at = closing.end;
|
|
copied = at;
|
|
bool* value_2 = &(result.changed);
|
|
(*value_2) = true;
|
|
}
|
|
declaration_Put(output, &(result.count), StringRangeAt(source, (int64_t)copied, (int64_t)source.length));
|
|
return result;
|
|
}
|
|
|
|
TextRewrite
|
|
declaration_RewriteLocalNames(String source, Slice names, Slice output)
|
|
{
|
|
TextRewrite result = {0};
|
|
String previous = StringLiteral("");
|
|
int64_t copied = 0LL;
|
|
int64_t at = 0LL;
|
|
while (at < (int64_t)(source).length) {
|
|
Scan token = scan_NextToken(source, at, 1, 1);
|
|
if (((TokenKind)(token.kind)) == TokenKind_Eof) {
|
|
break;
|
|
}
|
|
int64_t comment = declaration_AfterComment(source, token.begin);
|
|
if (comment != token.begin) {
|
|
at = comment;
|
|
continue;
|
|
}
|
|
String spelling = StringRangeAt(source, (int64_t)token.begin, (int64_t)token.end);
|
|
bool label = false;
|
|
if ((StringEqual(previous, StringLiteral("{")) || StringEqual(previous, StringLiteral(",")) || (StringEqual(previous, StringLiteral("("))))) {
|
|
Scan next = scan_NextToken(source, token.end, 1, 1);
|
|
label = StringEqual(StringRangeAt(source, (int64_t)next.begin, (int64_t)next.end), StringLiteral("="));
|
|
}
|
|
if (((TokenKind)(token.kind)) == TokenKind_Ident && !StringEqual(previous, StringLiteral(".")) && !label) {
|
|
{
|
|
int64_t range_first_21 = 0LL;
|
|
int64_t range_last_21 = (int64_t)((uint64_t)((int64_t)(names).length) - UINT64_C(1));
|
|
int64_t index = range_last_21;
|
|
if (index >= range_first_21) for (;;) {
|
|
if (!StringEqual((((NameReplacement *)(names).data)[index]).source, spelling)) {
|
|
if (index == range_first_21) {
|
|
break;
|
|
}
|
|
index = (int64_t)((uint64_t)index - UINT64_C(1));
|
|
continue;
|
|
}
|
|
declaration_Put(output, &(result.count), StringRangeAt(source, (int64_t)copied, (int64_t)token.begin));
|
|
declaration_Put(output, &(result.count), (((NameReplacement *)(names).data)[index]).target);
|
|
copied = token.end;
|
|
bool* value_0 = &(result.changed);
|
|
(*value_0) = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
previous = spelling;
|
|
at = token.end;
|
|
}
|
|
declaration_Put(output, &(result.count), StringRangeAt(source, (int64_t)copied, (int64_t)source.length));
|
|
return result;
|
|
}
|
|
|
|
SymmetricRewrite
|
|
declaration_RewriteSymmetric(String source, Slice header_output, Slice wrapper_output, int64_t name_limit)
|
|
{
|
|
SymmetricRewrite result = {0};
|
|
int64_t directive = -1LL;
|
|
int64_t end = 0LL;
|
|
int64_t at = 0LL;
|
|
int32_t depth = 0;
|
|
while (at < (int64_t)(source).length) {
|
|
Scan token = scan_NextToken(source, at, 1, 1);
|
|
if (((TokenKind)(token.kind)) == TokenKind_Eof) {
|
|
break;
|
|
}
|
|
int64_t comment = declaration_AfterComment(source, token.begin);
|
|
if (comment != token.begin) {
|
|
at = comment;
|
|
continue;
|
|
}
|
|
String spelling = StringRangeAt(source, (int64_t)token.begin, (int64_t)token.end);
|
|
if ((((StringEqual(spelling, StringLiteral("("))) || StringEqual(spelling, StringLiteral("["))) || StringEqual(spelling, StringLiteral("{")))) {
|
|
depth = (int32_t)((uint32_t)depth + 1u);
|
|
} else if ((((StringEqual(spelling, StringLiteral(")"))) || StringEqual(spelling, StringLiteral("]"))) || StringEqual(spelling, StringLiteral("}")))) {
|
|
depth = (int32_t)((uint32_t)depth - 1u);
|
|
}
|
|
if (StringEqual(spelling, StringLiteral("{")) && depth == 1) {
|
|
break;
|
|
}
|
|
if (depth == 0 && ((TokenKind)(token.kind)) == TokenKind_Directive && StringEqual(spelling, StringLiteral("#symmetric"))) {
|
|
if (directive >= 0LL) {
|
|
DeclarationError* value_0 = &(result.error);
|
|
(*value_0) = DeclarationError_SymmetricModifier;
|
|
return result;
|
|
}
|
|
directive = token.begin;
|
|
end = token.end;
|
|
}
|
|
at = token.end;
|
|
}
|
|
if (directive < 0LL) {
|
|
declaration_Put(header_output, &(result.header_count), source);
|
|
return result;
|
|
}
|
|
bool* value_1 = &(result.present);
|
|
(*value_1) = true;
|
|
declaration_Put(header_output, &(result.header_count), StringRangeAt(source, (int64_t)0LL, (int64_t)directive));
|
|
declaration_Put(header_output, &(result.header_count), StringRangeAt(source, (int64_t)end, (int64_t)source.length));
|
|
ProcedureHeader header = source_ProcedureHeaderParts(source);
|
|
bool value_2 = (int64_t)(header.name).length < 9LL;
|
|
if (!value_2) {
|
|
String value_3 = header.name;
|
|
value_2 = (!StringEqual(StringRangeAt(value_3, (int64_t)0LL, (int64_t)9LL), StringLiteral("operator_")));
|
|
}
|
|
if (value_2 || (int64_t)(header.name).length >= name_limit) {
|
|
DeclarationError* value_4 = &(result.error);
|
|
(*value_4) = DeclarationError_SymmetricParameters;
|
|
return result;
|
|
}
|
|
SourcePart first = source_text_NextSourcePart(header.parameters, 0LL);
|
|
SourcePart second = source_text_NextSourcePart(header.parameters, first.next);
|
|
if (first.next < 0LL || second.next >= 0LL) {
|
|
DeclarationError* value_5 = &(result.error);
|
|
(*value_5) = DeclarationError_SymmetricParameters;
|
|
return result;
|
|
}
|
|
String value_6 = header.parameters;
|
|
String value_7 = StringRangeAt(value_6, (int64_t)first.begin, (int64_t)first.end);
|
|
String value_8 = StringView(NULL, 0);
|
|
{
|
|
String value_10 = value_7;
|
|
SourceRange value_11 = source_text_TrimRange(value_10);
|
|
value_8 = StringRangeAt(value_10, (int64_t)value_11.begin, (int64_t)value_11.end);
|
|
}
|
|
String left = value_8;
|
|
String value_12 = header.parameters;
|
|
String value_13 = StringRangeAt(value_12, (int64_t)second.begin, (int64_t)second.end);
|
|
String value_14 = StringView(NULL, 0);
|
|
{
|
|
String value_16 = value_13;
|
|
SourceRange value_17 = source_text_TrimRange(value_16);
|
|
value_14 = StringRangeAt(value_16, (int64_t)value_17.begin, (int64_t)value_17.end);
|
|
}
|
|
String right = value_14;
|
|
int64_t left_colon = declaration_Find(left, StringLiteral(":"));
|
|
int64_t right_colon = declaration_Find(right, StringLiteral(":"));
|
|
if (left_colon < 0LL || right_colon < 0LL) {
|
|
DeclarationError* value_18 = &(result.error);
|
|
(*value_18) = DeclarationError_SymmetricParameters;
|
|
return result;
|
|
}
|
|
String value_19 = StringRangeAt(left, (int64_t)0LL, (int64_t)left_colon);
|
|
String value_20 = StringView(NULL, 0);
|
|
{
|
|
String value_22 = value_19;
|
|
SourceRange value_23 = source_text_TrimRange(value_22);
|
|
value_20 = StringRangeAt(value_22, (int64_t)value_23.begin, (int64_t)value_23.end);
|
|
}
|
|
String left_name = value_20;
|
|
String value_24 = StringRangeAt(right, (int64_t)0LL, (int64_t)right_colon);
|
|
String value_25 = StringView(NULL, 0);
|
|
{
|
|
String value_27 = value_24;
|
|
SourceRange value_28 = source_text_TrimRange(value_27);
|
|
value_25 = StringRangeAt(value_27, (int64_t)value_28.begin, (int64_t)value_28.end);
|
|
}
|
|
String right_name = value_25;
|
|
bool value_29 = (int64_t)(left_name).length >= name_limit || (int64_t)(right_name).length >= name_limit;
|
|
if (!value_29) {
|
|
bool value_30 = source_IdentifierText(left_name, false);
|
|
value_29 = !value_30;
|
|
}
|
|
bool value_31 = value_29;
|
|
if (!value_31) {
|
|
bool value_32 = source_IdentifierText(right_name, false);
|
|
value_31 = !value_32;
|
|
}
|
|
if (value_31) {
|
|
DeclarationError* value_33 = &(result.error);
|
|
(*value_33) = DeclarationError_SymmetricParameters;
|
|
return result;
|
|
}
|
|
uint8_t first_type[128] = {0};
|
|
uint8_t second_type[128] = {0};
|
|
uint8_t result_type[128] = {0};
|
|
String value_34 = StringRangeAt(left, (int64_t)((int64_t)((uint64_t)left_colon + UINT64_C(1))), (int64_t)left.length);
|
|
String value_35 = StringView(NULL, 0);
|
|
{
|
|
String value_37 = value_34;
|
|
SourceRange value_38 = source_text_TrimRange(value_37);
|
|
value_35 = StringRangeAt(value_37, (int64_t)value_38.begin, (int64_t)value_38.end);
|
|
}
|
|
Slice value_39 = {first_type, 128};
|
|
int64_t left_count = source_NormalizeTypeSpacing(value_35, value_39);
|
|
String value_40 = StringRangeAt(right, (int64_t)((int64_t)((uint64_t)right_colon + UINT64_C(1))), (int64_t)right.length);
|
|
String value_41 = StringView(NULL, 0);
|
|
{
|
|
String value_43 = value_40;
|
|
SourceRange value_44 = source_text_TrimRange(value_43);
|
|
value_41 = StringRangeAt(value_43, (int64_t)value_44.begin, (int64_t)value_44.end);
|
|
}
|
|
Slice value_45 = {second_type, 128};
|
|
int64_t right_count = source_NormalizeTypeSpacing(value_41, value_45);
|
|
if (left_count == 0LL || right_count == 0LL || left_count >= 128LL || right_count >= 128LL) {
|
|
DeclarationError* value_46 = &(result.error);
|
|
(*value_46) = DeclarationError_SymmetricParameters;
|
|
return result;
|
|
}
|
|
Slice value_47 = {first_type, 128};
|
|
Slice value_48 = SliceRangeAt(value_47, (int64_t)0LL, (int64_t)left_count, sizeof(uint8_t));
|
|
String left_type = StringView((const char *)(value_48).data, (size_t)(value_48).length);
|
|
Slice value_49 = {second_type, 128};
|
|
Slice value_50 = SliceRangeAt(value_49, (int64_t)0LL, (int64_t)right_count, sizeof(uint8_t));
|
|
String right_type = StringView((const char *)(value_50).data, (size_t)(value_50).length);
|
|
if (StringEqual(left_type, right_type)) {
|
|
return result;
|
|
}
|
|
Slice value_51 = {result_type, 128};
|
|
int64_t result_count = source_NormalizeTypeSpacing(header.result, value_51);
|
|
if (result_count >= 128LL) {
|
|
DeclarationError* value_52 = &(result.error);
|
|
(*value_52) = DeclarationError_SymmetricParameters;
|
|
return result;
|
|
}
|
|
Slice value_53 = {result_type, 128};
|
|
Slice value_54 = SliceRangeAt(value_53, (int64_t)0LL, (int64_t)result_count, sizeof(uint8_t));
|
|
String return_type = StringView((const char *)(value_54).data, (size_t)(value_54).length);
|
|
bool* value_55 = &(result.needed);
|
|
(*value_55) = true;
|
|
declaration_Put(wrapper_output, &(result.count), header.name);
|
|
declaration_Put(wrapper_output, &(result.count), StringLiteral(" :: ("));
|
|
declaration_Put(wrapper_output, &(result.count), right_name);
|
|
declaration_Put(wrapper_output, &(result.count), StringLiteral(": "));
|
|
declaration_Put(wrapper_output, &(result.count), right_type);
|
|
declaration_Put(wrapper_output, &(result.count), StringLiteral(", "));
|
|
declaration_Put(wrapper_output, &(result.count), left_name);
|
|
declaration_Put(wrapper_output, &(result.count), StringLiteral(": "));
|
|
declaration_Put(wrapper_output, &(result.count), left_type);
|
|
declaration_Put(wrapper_output, &(result.count), StringLiteral(")"));
|
|
if (!StringEqual(return_type, StringLiteral("void"))) {
|
|
declaration_Put(wrapper_output, &(result.count), StringLiteral(" -> "));
|
|
declaration_Put(wrapper_output, &(result.count), return_type);
|
|
}
|
|
declaration_Put(wrapper_output, &(result.count), StringLiteral(" { return "));
|
|
declaration_Put(wrapper_output, &(result.count), header.name);
|
|
declaration_Put(wrapper_output, &(result.count), StringLiteral("("));
|
|
declaration_Put(wrapper_output, &(result.count), left_name);
|
|
declaration_Put(wrapper_output, &(result.count), StringLiteral(", "));
|
|
declaration_Put(wrapper_output, &(result.count), right_name);
|
|
declaration_Put(wrapper_output, &(result.count), StringLiteral("); }"));
|
|
return result;
|
|
}
|
|
|
|
bool
|
|
declaration_PrintfSpelling(String format, bool loose)
|
|
{
|
|
bool found = false;
|
|
int64_t at = 0LL;
|
|
while (at < (int64_t)(format).length) {
|
|
if ((uint8_t)format.data[at] == 92) {
|
|
at = (int64_t)((uint64_t)at + UINT64_C(2));
|
|
continue;
|
|
}
|
|
if ((uint8_t)format.data[at] != 37) {
|
|
at = (int64_t)((uint64_t)at + UINT64_C(1));
|
|
continue;
|
|
}
|
|
if ((int64_t)((uint64_t)at + UINT64_C(1)) < (int64_t)(format).length && (uint8_t)format.data[((int64_t)((uint64_t)at + UINT64_C(1)))] == 37) {
|
|
at = (int64_t)((uint64_t)at + UINT64_C(2));
|
|
continue;
|
|
}
|
|
int64_t next = (int64_t)((uint64_t)at + UINT64_C(1));
|
|
bool precision = false;
|
|
while (true) {
|
|
bool value_0 = next < (int64_t)(format).length;
|
|
if (value_0) {
|
|
uint8_t value_1 = (uint8_t)format.data[next];
|
|
bool value_2 = false;
|
|
{
|
|
uint8_t value_4 = value_1;
|
|
value_2 = value_4 == 45 || value_4 == 43 || value_4 == 35 || value_4 == 46 || (value_4 >= 48 && value_4 <= 57);
|
|
}
|
|
value_0 = value_2;
|
|
}
|
|
if (!value_0) { break; }
|
|
precision = precision || (uint8_t)format.data[next] == 46;
|
|
next = (int64_t)((uint64_t)next + UINT64_C(1));
|
|
}
|
|
while (next < (int64_t)(format).length && ((uint8_t)format.data[next] == 108 || (uint8_t)format.data[next] == 104 || (uint8_t)format.data[next] == 122)) {
|
|
next = (int64_t)((uint64_t)next + UINT64_C(1));
|
|
}
|
|
bool value_5 = next < (int64_t)(format).length;
|
|
if (value_5) {
|
|
bool value_6 = (int64_t)((uint64_t)next + UINT64_C(1)) == (int64_t)(format).length;
|
|
if (!value_6) {
|
|
uint8_t value_7 = (uint8_t)format.data[((int64_t)((uint64_t)next + UINT64_C(1)))];
|
|
bool value_8 = false;
|
|
{
|
|
uint8_t value_10 = value_7;
|
|
value_8 = (value_10 >= 97 && value_10 <= 122) || (value_10 >= 65 && value_10 <= 90);
|
|
}
|
|
value_6 = !value_8;
|
|
}
|
|
value_5 = value_6;
|
|
}
|
|
bool conversion = value_5;
|
|
if (conversion) {
|
|
uint8_t byte = (uint8_t)format.data[next];
|
|
bool strict = byte == 100 || byte == 105 || byte == 117 || byte == 118 || byte == 102 || (byte == 115 && !precision);
|
|
conversion = strict || (loose && declaration_IsPrintfConversion(byte));
|
|
}
|
|
if (conversion) {
|
|
found = true;
|
|
} else if (!loose) {
|
|
return false;
|
|
}
|
|
at = (int64_t)((uint64_t)next + UINT64_C(1));
|
|
}
|
|
return found;
|
|
}
|
|
|
|
int32_t
|
|
FormatPrintfSpelling(uint8_t* format, int32_t loose)
|
|
{
|
|
(void)sizeof("ziran.c.export-root");
|
|
CText view = {.data = format};
|
|
while (format[view.count] != 0) {
|
|
int64_t* value_0 = &(view.count);
|
|
(*value_0) = (int64_t)((uint64_t)((*value_0)) + UINT64_C(1));
|
|
}
|
|
bool value_1 = declaration_PrintfSpelling(((String*)(&(view)))[0], loose != 0);
|
|
int32_t value_2 = 0;
|
|
if (value_1) {
|
|
value_2 = 1;
|
|
} else {
|
|
value_2 = 0;
|
|
}
|
|
return value_2;
|
|
}
|
|
|
|
static bool
|
|
declaration_IsAsciiLetter(uint8_t byte)
|
|
{
|
|
return (byte >= 97 && byte <= 122) || (byte >= 65 && byte <= 90);
|
|
}
|
|
|
|
static bool
|
|
declaration_IsPrintfFlag(uint8_t byte)
|
|
{
|
|
return byte == 45 || byte == 43 || byte == 35 || byte == 46 || (byte >= 48 && byte <= 57);
|
|
}
|
|
|
|
static bool
|
|
declaration_IsPrintfConversion(uint8_t byte)
|
|
{
|
|
{
|
|
String value_0 = StringLiteral("diuxXocsfFeEgGpvqtb");
|
|
String loop_view_0 = StringRangeAt(value_0, (int64_t)0, (int64_t)value_0.length);
|
|
int64_t loop_count_0 = (int64_t)(loop_view_0).length;
|
|
int64_t loop_cursor_0 = 0LL;
|
|
while (loop_cursor_0 < loop_count_0) {
|
|
int64_t loop_index_0 = loop_cursor_0;
|
|
uint8_t conversion = (uint8_t)loop_view_0.data[loop_index_0];
|
|
if (byte == conversion) {
|
|
return true;
|
|
}
|
|
loop_cursor_0 = (int64_t)((uint64_t)loop_cursor_0 + UINT64_C(1));
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
static void
|
|
declaration_AddScanPiece(BuilderPrintScan* result, BuilderPrintPiece piece)
|
|
{
|
|
if (result->count == 64) {
|
|
DeclarationError* value_0 = &(result->error);
|
|
(*value_0) = DeclarationError_BuilderPieces;
|
|
return;
|
|
}
|
|
BuilderPrintPiece* value_1 = &(result->pieces[result->count]);
|
|
(*value_1) = piece;
|
|
int32_t* value_2 = &(result->count);
|
|
(*value_2) = (int32_t)((uint32_t)((*value_2)) + 1u);
|
|
}
|
|
|
|
void
|
|
declaration_BuilderPrintLiteral(Slice output, int64_t* used, String text)
|
|
{
|
|
int64_t at = 0LL;
|
|
while (at < (int64_t)(text).length) {
|
|
uint8_t byte = (uint8_t)text.data[at];
|
|
declaration_Put(output, used, StringRangeAt(text, (int64_t)at, (int64_t)((int64_t)((uint64_t)at + UINT64_C(1)))));
|
|
at = (int64_t)((uint64_t)at + UINT64_C(1));
|
|
if (byte == 92 && at < (int64_t)(text).length) {
|
|
declaration_Put(output, used, StringRangeAt(text, (int64_t)at, (int64_t)((int64_t)((uint64_t)at + UINT64_C(1)))));
|
|
at = (int64_t)((uint64_t)at + UINT64_C(1));
|
|
} else if (byte == 37 && at < (int64_t)(text).length && (uint8_t)text.data[at] == 37) {
|
|
at = (int64_t)((uint64_t)at + UINT64_C(1));
|
|
}
|
|
}
|
|
}
|
|
|
|
BuilderPrintScan
|
|
declaration_ScanPrintFormat(String format, int32_t arguments)
|
|
{
|
|
BuilderPrintScan result = {0};
|
|
if (declaration_PrintfSpelling(format, false)) {
|
|
DeclarationError* value_0 = &(result.error);
|
|
(*value_0) = DeclarationError_BuilderPrintf;
|
|
return result;
|
|
}
|
|
int32_t argument = 0;
|
|
int64_t begin = 0LL;
|
|
int64_t at = 0LL;
|
|
while (at < (int64_t)(format).length) {
|
|
uint8_t byte = (uint8_t)format.data[at];
|
|
if (byte == 92 && (int64_t)((uint64_t)at + UINT64_C(1)) < (int64_t)(format).length) {
|
|
at = (int64_t)((uint64_t)at + UINT64_C(2));
|
|
continue;
|
|
}
|
|
if (byte == 37 && (int64_t)((uint64_t)at + UINT64_C(1)) < (int64_t)(format).length && (uint8_t)format.data[((int64_t)((uint64_t)at + UINT64_C(1)))] == 37) {
|
|
at = (int64_t)((uint64_t)at + UINT64_C(2));
|
|
continue;
|
|
}
|
|
if (byte != 37) {
|
|
at = (int64_t)((uint64_t)at + UINT64_C(1));
|
|
continue;
|
|
}
|
|
if (argument == arguments) {
|
|
DeclarationError* value_1 = &(result.error);
|
|
bool value_2 = declaration_PrintfSpelling(format, true);
|
|
DeclarationError value_3 = (DeclarationError)(0);
|
|
if (value_2) {
|
|
value_3 = DeclarationError_BuilderPrintf;
|
|
} else {
|
|
value_3 = DeclarationError_BuilderPercent;
|
|
}
|
|
(*value_1) = value_3;
|
|
return result;
|
|
}
|
|
if (at > begin) {
|
|
BuilderPrintScan* value_4 = &(result);
|
|
BuilderPrintPiece value_5 = (BuilderPrintPiece){.literal = true, .text = StringRangeAt(format, (int64_t)begin, (int64_t)at), .argument = 0};
|
|
{
|
|
BuilderPrintScan* value_7 = value_4;
|
|
BuilderPrintPiece value_8 = value_5;
|
|
if (value_7->count == 64) {
|
|
DeclarationError* value_9 = &(value_7->error);
|
|
(*value_9) = DeclarationError_BuilderPieces;
|
|
goto value_6;
|
|
}
|
|
BuilderPrintPiece* value_10 = &(value_7->pieces[value_7->count]);
|
|
(*value_10) = value_8;
|
|
int32_t* value_11 = &(value_7->count);
|
|
(*value_11) = (int32_t)((uint32_t)((*value_11)) + 1u);
|
|
value_6: ;
|
|
}
|
|
}
|
|
if (((DeclarationError)(result.error)) != DeclarationError_None) {
|
|
return result;
|
|
}
|
|
BuilderPrintScan* value_12 = &(result);
|
|
BuilderPrintPiece value_13 = (BuilderPrintPiece){.literal = false, .text = StringLiteral(""), .argument = argument};
|
|
{
|
|
BuilderPrintScan* value_15 = value_12;
|
|
BuilderPrintPiece value_16 = value_13;
|
|
if (value_15->count == 64) {
|
|
DeclarationError* value_17 = &(value_15->error);
|
|
(*value_17) = DeclarationError_BuilderPieces;
|
|
goto value_14;
|
|
}
|
|
BuilderPrintPiece* value_18 = &(value_15->pieces[value_15->count]);
|
|
(*value_18) = value_16;
|
|
int32_t* value_19 = &(value_15->count);
|
|
(*value_19) = (int32_t)((uint32_t)((*value_19)) + 1u);
|
|
value_14: ;
|
|
}
|
|
if (((DeclarationError)(result.error)) != DeclarationError_None) {
|
|
return result;
|
|
}
|
|
argument = (int32_t)((uint32_t)argument + 1u);
|
|
at = (int64_t)((uint64_t)at + UINT64_C(1));
|
|
begin = at;
|
|
}
|
|
if (argument != arguments) {
|
|
DeclarationError* value_20 = &(result.error);
|
|
bool value_21 = declaration_PrintfSpelling(format, true);
|
|
DeclarationError value_22 = (DeclarationError)(0);
|
|
if (value_21) {
|
|
value_22 = DeclarationError_BuilderPrintf;
|
|
} else {
|
|
value_22 = DeclarationError_BuilderArguments;
|
|
}
|
|
(*value_20) = value_22;
|
|
return result;
|
|
}
|
|
if (at > begin) {
|
|
BuilderPrintScan* value_23 = &(result);
|
|
BuilderPrintPiece value_24 = (BuilderPrintPiece){.literal = true, .text = StringRangeAt(format, (int64_t)begin, (int64_t)at), .argument = 0};
|
|
{
|
|
BuilderPrintScan* value_26 = value_23;
|
|
BuilderPrintPiece value_27 = value_24;
|
|
if (value_26->count == 64) {
|
|
DeclarationError* value_28 = &(value_26->error);
|
|
(*value_28) = DeclarationError_BuilderPieces;
|
|
goto value_25;
|
|
}
|
|
BuilderPrintPiece* value_29 = &(value_26->pieces[value_26->count]);
|
|
(*value_29) = value_27;
|
|
int32_t* value_30 = &(value_26->count);
|
|
(*value_30) = (int32_t)((uint32_t)((*value_30)) + 1u);
|
|
value_25: ;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
PrintRewrite
|
|
declaration_BuilderPrintPieces(String source, Slice output, int32_t maximum)
|
|
{
|
|
PrintRewrite result = {0};
|
|
String value_0 = source;
|
|
String value_1 = StringView(NULL, 0);
|
|
{
|
|
String value_3 = value_0;
|
|
SourceRange value_4 = source_text_TrimRange(value_3);
|
|
value_1 = StringRangeAt(value_3, (int64_t)value_4.begin, (int64_t)value_4.end);
|
|
}
|
|
String call = value_1;
|
|
bool value_5 = source_StartsWord(call, StringLiteral("BuilderPrint"));
|
|
if (!value_5) {
|
|
return result;
|
|
}
|
|
int64_t opening = source_text_SkipSpace(call, 12LL, true);
|
|
if (opening >= (int64_t)(call).length || (uint8_t)call.data[opening] != 40) {
|
|
return result;
|
|
}
|
|
int64_t closing = source_ClosingParenthesis(StringRangeAt(call, (int64_t)opening, (int64_t)call.length));
|
|
if (closing < 0LL) {
|
|
return result;
|
|
}
|
|
closing = (int64_t)((uint64_t)closing + (uint64_t)opening);
|
|
String value_6 = StringRangeAt(call, (int64_t)((int64_t)((uint64_t)closing + UINT64_C(1))), (int64_t)call.length);
|
|
String value_7 = StringView(NULL, 0);
|
|
{
|
|
String value_9 = value_6;
|
|
SourceRange value_10 = source_text_TrimRange(value_9);
|
|
value_7 = StringRangeAt(value_9, (int64_t)value_10.begin, (int64_t)value_10.end);
|
|
}
|
|
String rest = value_7;
|
|
if (!StringEqual(rest, StringLiteral("")) && !StringEqual(rest, StringLiteral(";"))) {
|
|
return result;
|
|
}
|
|
String inner = StringRangeAt(call, (int64_t)((int64_t)((uint64_t)opening + UINT64_C(1))), (int64_t)closing);
|
|
String parts[64] = {0};
|
|
int32_t count = 0;
|
|
int64_t at = 0LL;
|
|
while (at >= 0LL) {
|
|
if (count == 64) {
|
|
DeclarationError* value_11 = &(result.error);
|
|
(*value_11) = DeclarationError_BuilderArgumentCount;
|
|
return result;
|
|
}
|
|
SourcePart range = source_text_NextSourcePart(inner, at);
|
|
String* value_12 = &(parts[count]);
|
|
String value_13 = StringRangeAt(inner, (int64_t)range.begin, (int64_t)range.end);
|
|
String value_14 = StringView(NULL, 0);
|
|
{
|
|
String value_16 = value_13;
|
|
SourceRange value_17 = source_text_TrimRange(value_16);
|
|
value_14 = StringRangeAt(value_16, (int64_t)value_17.begin, (int64_t)value_17.end);
|
|
}
|
|
(*value_12) = value_14;
|
|
count = (int32_t)((uint32_t)count + 1u);
|
|
at = range.next;
|
|
}
|
|
String format = (parts)[1];
|
|
if (count < 2 || (int64_t)(format).length < 2LL || (uint8_t)format.data[0] != 34 || (uint8_t)format.data[((int64_t)((uint64_t)((int64_t)(format).length) - UINT64_C(1)))] != 34) {
|
|
DeclarationError* value_18 = &(result.error);
|
|
(*value_18) = DeclarationError_BuilderFormat;
|
|
return result;
|
|
}
|
|
BuilderPrintScan scan = declaration_ScanPrintFormat(StringRangeAt(format, (int64_t)1LL, (int64_t)((int64_t)((uint64_t)((int64_t)(format).length) - UINT64_C(1)))), (int32_t)((uint32_t)count - 2u));
|
|
if (((DeclarationError)(scan.error)) != DeclarationError_None) {
|
|
DeclarationError* value_19 = &(result.error);
|
|
(*value_19) = (DeclarationError)(scan.error);
|
|
return result;
|
|
}
|
|
{
|
|
int32_t range_first_42 = 0;
|
|
int32_t range_last_42 = (int32_t)((uint32_t)(scan.count) - 1u);
|
|
int32_t index = range_first_42;
|
|
if (index <= range_last_42) for (;;) {
|
|
BuilderPrintPiece piece = (scan.pieces)[index];
|
|
String value = piece.text;
|
|
if (!piece.literal) {
|
|
value = (parts)[((int32_t)(2u + (uint32_t)(piece.argument)))];
|
|
}
|
|
declaration_AddPrintPiece(&(result), output, maximum, (parts)[0], value, piece.literal);
|
|
if (((DeclarationError)(result.error)) != DeclarationError_None) {
|
|
return result;
|
|
}
|
|
if (index == range_last_42) {
|
|
break;
|
|
}
|
|
index = (int32_t)((uint32_t)index + 1u);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
static void
|
|
declaration_AddPrintPiece(PrintRewrite* result, Slice output, int32_t maximum, String builder, String value, bool literal)
|
|
{
|
|
if (result->statements == 64 || result->statements >= maximum) {
|
|
DeclarationError* value_0 = &(result->error);
|
|
(*value_0) = DeclarationError_BuilderPieces;
|
|
return;
|
|
}
|
|
Slice slot = {0};
|
|
int64_t value_1 = (int64_t)(result->statements);
|
|
int64_t value_2 = (int64_t)(output).length;
|
|
if (value_1 < value_2) {
|
|
slot = (((StatementOutput *)(output).data)[result->statements]).bytes;
|
|
}
|
|
int64_t used = 0LL;
|
|
declaration_Put(slot, &(used), StringLiteral("Append("));
|
|
declaration_Put(slot, &(used), builder);
|
|
declaration_Put(slot, &(used), StringLiteral(", "));
|
|
if (literal) {
|
|
declaration_Put(slot, &(used), StringLiteral("\""));
|
|
declaration_BuilderPrintLiteral(slot, &(used), value);
|
|
declaration_Put(slot, &(used), StringLiteral("\""));
|
|
} else {
|
|
declaration_Put(slot, &(used), value);
|
|
}
|
|
declaration_Put(slot, &(used), StringLiteral(");"));
|
|
int64_t* value_3 = &(result->lengths[result->statements]);
|
|
(*value_3) = used;
|
|
int32_t* value_4 = &(result->statements);
|
|
(*value_4) = (int32_t)((uint32_t)((*value_4)) + 1u);
|
|
}
|