/** * A high-level intermediate representation used by XCompile. * Copyright (c) 2025 James Prevett */ import type { TypeName } from 'memium/primitives'; export type BuiltinType = TypeName | 'void' | 'bool'; export declare function isBuiltin(type: string): type is BuiltinType; export declare function baseType(type: Type): string; export type TypeQualifier = string; export type Type = { kind: 'plain'; text: string; raw?: Type; attributes?: string[]; } | { kind: 'array'; length: number | null; element: Type; } | { kind: 'ref'; to: Type; restricted?: boolean; } | { kind: 'function'; returns: Type; args: Type[]; } | { kind: 'qual'; qualifier: TypeQualifier; inner: Type; } | { kind: 'namespaced'; namespace: string; inner: Type; } | { kind: 'typeof'; target: Type; }; export declare function typeHasQualifier(type: Type | null, qual: TypeQualifier): boolean; export type RecordInitializer = { field: string; value: Value; }[]; export type ValueContents = { toString(): string; } | string | RecordInitializer; export interface Value { kind: 'value'; type: Type; content: ValueContents; } export type Postfix = { type: 'bracket_access'; key: Expression[]; } | { type: 'call'; args: Expression[]; } | { type: 'access' | 'access_ref'; key: string; } | { type: 'increment' | 'decrement'; }; export interface Postfixed { kind: 'postfixed'; primary: Expression[]; post: Postfix; } export interface Cast { kind: 'cast'; type: Type; value: Expression; } export interface Unary { kind: 'unary'; operator: '++' | '--' | '~' | '!' | '+' | '-' | '&' | '*'; expression: Expression[]; } export interface Binary { kind: 'binary'; operator: '&' | '*' | '+' | '-' | '/' | '%' | '==' | '===' | '!=' | '>=' | '<=' | '^' | '|' | '&&' | '||' | '??' | '<<<' | '>>>' | '<<' | '>>' | '<' | '>' | ','; left: Expression[]; right: Expression[]; } export interface Assignment { kind: 'assignment'; operator: '=' | '*=' | '/=' | '%=' | '+=' | '-=' | '&=' | '^=' | '|=' | '>>=' | '<<='; left: Expression[]; right: Expression[]; } export interface Ternary { kind: 'ternary'; condition: Expression[]; true: Expression[]; false: Expression[]; } export type Expression = Assignment | Unary | Binary | Ternary | Cast | Postfixed | Value; export interface Conditional { condition: Expression[]; body: Unit[]; } export type StorageClass = 'extern' | 'static'; export interface Declaration { kind: 'declaration' | 'field' | 'parameter'; name: string; type: Type | null; initializer?: Value; storage?: StorageClass; index?: number; exported?: boolean; } export interface Function { kind: 'function'; returns: Type; parameters: Declaration[]; body: Unit[]; name: string; storage?: StorageClass; exported?: boolean; } export interface RecordLike { kind: 'struct' | 'class' | 'union' | 'enum'; name: string; complete?: boolean; fields: Declaration[]; subRecords: RecordLike[]; exported?: boolean; } export type Unit = { kind: 'case'; matches: Expression; } | { kind: 'default'; } | { kind: 'comment'; text: string; } | Declaration | { kind: 'enum_field'; name: string; value?: Value; type?: Type; } | Expression | ({ kind: 'for'; init: Expression[]; action: Expression[]; } & Conditional) | Function | ({ kind: 'if'; else?: Unit[]; } & Conditional) | { kind: 'goto'; target: string; } | { kind: 'label'; name: string; } | { kind: 'break' | 'continue'; target?: string; } | RecordLike | { kind: 'return'; value: Expression[]; } | { kind: 'switch'; expression: Expression[]; body: Unit[]; } | { kind: 'type_alias'; name: string; value: Type; exported?: boolean; } | ({ kind: 'while'; isDo: boolean; } & Conditional); export declare const textFormat = 0; export declare function text(u: Unit): string;