import * as xir from '../ir.js'; interface _Location { offset: number; line: number; col: number; tokLen: number; file?: string; includedFrom?: { file: string; }; isMacroArgExpansion?: boolean; } export type Location = _Location | { spellingLoc: _Location; expansionLoc: _Location; }; export type ValueCategory = 'prvalue' | 'lvalue' | 'rvalue'; export interface TypeInfo { desugaredQualType?: string; qualType: string; typeAliasDeclId?: string; } export interface GenericNode { /** Hexadecimal ID for the node, e.g. "0x..." */ id: string; /** The kind of the node */ kind: string; range?: { begin: Location; end: Location; }; type: TypeInfo; inner?: Node[]; name?: string; } export interface Statement extends GenericNode { kind: 'AttributedStmt' | 'BreakStmt' | 'CaseStmt' | 'CompoundStmt' | 'DeclStmt' | 'DefaultStmt' | 'DoStmt' | 'ForStmt' | 'NullStmt' | 'ReturnStmt' | 'StaticAssert' | 'SwitchStmt' | 'WhileStmt'; inner: Node[]; } export interface IfStmt extends GenericNode { kind: 'IfStmt'; hasElse?: boolean; } export interface Label extends GenericNode { kind: 'LabelStmt'; declId: string; name: string; } export interface Goto extends GenericNode { kind: 'GotoStmt'; targetLabelDeclId: string; inner: never; } export interface MiscType extends GenericNode { kind: 'BuiltinType' | 'ParenType' | 'PointerType'; } export interface QualType extends GenericNode { kind: 'QualType'; qualifiers: 'const' | 'volatile'; } interface SubDecl { id: string; kind: string; name: string; } export interface DeclType extends GenericNode { kind: `${T}Type`; decl: SubDecl & { kind: `${T}Decl`; }; } export interface ElaboratedType extends GenericNode { kind: 'ElaboratedType'; ownedTagDecl?: SubDecl; } export interface ConstantArrayType extends GenericNode { kind: 'ConstantArrayType'; size: number; } export interface FunctionProtoType extends GenericNode { kind: 'FunctionProtoType'; cc?: 'cdecl'; loc: never; } export type Type = MiscType | QualType | DeclType | ElaboratedType | ConstantArrayType | FunctionProtoType; export type StorageClass = 'extern' | 'static' | 'register'; export interface Declaration extends GenericNode { kind: 'EnumConstantDecl' | 'EnumDecl' | 'FieldDecl' | 'FunctionDecl' | 'IndirectFieldDecl' | 'ParmVarDecl' | 'StaticAssertDecl' | 'RecordDecl' | 'TranslationUnitDecl' | 'TypedefDecl' | 'VarDecl'; isImplicit?: boolean; init?: 'c'; /** Only on fields */ isBitfield?: boolean; storageClass?: StorageClass; isUsed?: boolean; isReferenced?: boolean; /** Only on functions */ variadic?: boolean; loc: Location; name: string; mangledName?: string; tagUsed?: 'struct' | 'union'; parentDeclContextId?: string; completeDefinition?: boolean; } export interface BinaryOperator extends GenericNode { kind: 'BinaryOperator'; opcode: '!=' | '%' | '&' | '&&' | '*' | '+' | ',' | '-' | '/' | '<' | '<<' | '<=' | '==' | '>' | '>>' | '^' | '__extension__' | '|' | '||'; isPostfix?: boolean; canOverflow?: boolean; inner: Node[]; } export interface CompoundAssignOperator extends GenericNode { kind: 'CompoundAssignOperator'; opcode: '=' | '*=' | '/=' | '%=' | '+=' | '-=' | '&=' | '^=' | '|=' | '>>=' | '<<='; inner: Node[]; } export interface UnaryOperator extends GenericNode { kind: 'UnaryOperator'; opcode: '!' | '&' | '*' | '+' | '++' | '-' | '--'; isPostfix?: boolean; inner: Node[]; } export interface RecoveryExpr extends GenericNode { kind: 'RecoveryExpr'; inner: Node[]; valueCategory: ValueCategory; } export interface UnexposedExpr extends GenericNode { kind: 'UnexposedExpr'; inner: Node[]; } export interface Value extends GenericNode { kind: 'ArraySubscriptExpr' | 'CStyleCastExpr' | 'CallExpr' | 'CharacterLiteral' | 'CompoundLiteralExpr' | 'ConditionalOperator' | 'ConstantExpr' | 'FloatingLiteral' | 'ImplicitCastExpr' | 'ImplicitValueInitExpr' | 'InitListExpr' | 'IntegerLiteral' | 'ParenExpr' | 'PredefinedExpr' | 'StmtExpr' | 'StringLiteral'; valueCategory: ValueCategory; value?: string | { toString(): string; }; } export interface UnaryExprOrTypeTraitExpr extends GenericNode { kind: 'UnaryExprOrTypeTraitExpr'; valueCategory: ValueCategory; value?: string; argType?: TypeInfo; } export interface TypeTraitExpr extends GenericNode { kind: 'TypeTraitExpr'; valueCategory: ValueCategory; type: TypeInfo; inner: Node[]; } export interface TypeOfExprType extends GenericNode { kind: 'TypeOfExprType'; type: TypeInfo; inner: Node[]; } export interface Member extends GenericNode { kind: 'MemberExpr'; valueCategory: ValueCategory; name: string; isArrow: boolean; referencedMemberDecl: string; inner: Node[]; } export interface DeclRefExpr extends GenericNode { kind: 'DeclRefExpr'; valueCategory: ValueCategory; referencedDecl: Declaration; inner: Node[]; nonOdrUseReason?: 'none' | 'unevaluated' | 'constant' | 'discarded'; } export interface Cast extends GenericNode { kind: 'CStyleCastExpr' | 'ImplicitCastExpr'; castKind: 'ArrayToPointerDecay' | 'BitCast' | 'BuiltinFnToFnPtr' | 'Dependent' | 'FunctionToPointerDecay' | 'IntegralCast' | 'IntegralToBoolean' | 'IntegralToFloating' | 'LValueToRValue' | 'NoOp' | 'NullToPointer' | 'PointerToIntegral' | 'ToVoid'; inner: Node[]; } export interface Attribute extends GenericNode { kind: 'AlignedAttr' | 'AllocAlignAttr' | 'AllocSizeAttr' | 'AsmLabelAttr' | 'BuiltinAttr' | 'C11NoReturnAttr' | 'ColdAttr' | 'ConstAttr' | 'FallThroughAttr' | 'FormatArgAttr' | 'FormatAttr' | 'NoThrowAttr' | 'NonNullAttr' | 'PureAttr' | 'RestrictAttr' | 'ReturnsNonNullAttr' | 'ReturnsTwiceAttr' | 'SentinelAttr' | 'WarnUnusedResultAttr'; implicit?: boolean; inherited?: boolean; } export interface DeprecatedAttr extends GenericNode { kind: 'DeprecatedAttr'; message: string; } export type Node = Attribute | BinaryOperator | Cast | CompoundAssignOperator | Declaration | DeclRefExpr | DeprecatedAttr | Goto | IfStmt | Label | Member | RecoveryExpr | Statement | Type | TypeOfExprType | TypeTraitExpr | UnaryOperator | UnaryExprOrTypeTraitExpr | UnexposedExpr | Value; interface ParseInternalOptions { /** * If set, interrupts will cascade upwards. */ cascade?: boolean; } export declare function parse(node: Node, opt?: ParseInternalOptions): T[]; export {};