use span::Node;
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub struct Identifier {
pub name: String,
}
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub enum Constant {
Integer(Integer),
Float(Float),
Character(String),
}
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub struct Integer {
pub base: IntegerBase,
pub number: Box<str>,
pub suffix: IntegerSuffix,
}
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub enum IntegerBase {
Decimal,
Octal,
Hexadecimal,
Binary,
}
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub struct IntegerSuffix {
pub size: IntegerSize,
pub unsigned: bool,
pub imaginary: bool,
}
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]
pub enum IntegerSize {
Int = 0,
Long,
LongLong,
}
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub struct Float {
pub base: FloatBase,
pub number: Box<str>,
pub suffix: FloatSuffix,
}
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub enum FloatBase {
Decimal,
Hexadecimal,
}
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub struct FloatSuffix {
pub format: FloatFormat,
pub imaginary: bool,
}
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub enum FloatFormat {
Float,
Double,
LongDouble,
TS18661Format(TS18661FloatType),
}
pub type StringLiteral = Vec<String>;
#[derive(Debug, PartialEq, Clone)]
pub enum Expression {
Identifier(Box<Node<Identifier>>),
Constant(Box<Node<Constant>>),
StringLiteral(Box<Node<StringLiteral>>),
GenericSelection(Box<Node<GenericSelection>>),
Member(Box<Node<MemberExpression>>),
Call(Box<Node<CallExpression>>),
CompoundLiteral(Box<Node<CompoundLiteral>>),
SizeOfTy(Box<Node<SizeOfTy>>),
SizeOfVal(Box<Node<SizeOfVal>>),
AlignOf(Box<Node<AlignOf>>),
UnaryOperator(Box<Node<UnaryOperatorExpression>>),
Cast(Box<Node<CastExpression>>),
BinaryOperator(Box<Node<BinaryOperatorExpression>>),
Conditional(Box<Node<ConditionalExpression>>),
Comma(Box<Vec<Node<Expression>>>),
OffsetOf(Box<Node<OffsetOfExpression>>),
VaArg(Box<Node<VaArgExpression>>),
Statement(Box<Node<Statement>>),
}
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub enum MemberOperator {
Direct,
Indirect,
}
#[derive(Debug, PartialEq, Clone)]
pub struct GenericSelection {
pub expression: Box<Node<Expression>>,
pub associations: Vec<Node<GenericAssociation>>,
}
#[derive(Debug, PartialEq, Clone)]
pub enum GenericAssociation {
Type(Node<GenericAssociationType>),
Default(Box<Node<Expression>>),
}
#[derive(Debug, PartialEq, Clone)]
pub struct GenericAssociationType {
pub type_name: Node<TypeName>,
pub expression: Box<Node<Expression>>,
}
#[derive(Debug, PartialEq, Clone)]
pub struct MemberExpression {
pub operator: Node<MemberOperator>,
pub expression: Box<Node<Expression>>,
pub identifier: Node<Identifier>,
}
#[derive(Debug, PartialEq, Clone)]
pub struct CallExpression {
pub callee: Box<Node<Expression>>,
pub arguments: Vec<Node<Expression>>,
}
#[derive(Debug, PartialEq, Clone)]
pub struct CompoundLiteral {
pub type_name: Node<TypeName>,
pub initializer_list: Vec<Node<InitializerListItem>>,
}
#[derive(Debug, PartialEq, Clone)]
pub struct SizeOfTy(pub Node<TypeName>);
#[derive(Debug, PartialEq, Clone)]
pub struct SizeOfVal(pub Box<Node<Expression>>);
#[derive(Debug, PartialEq, Clone)]
pub struct AlignOf(pub Box<Node<TypeName>>);
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub enum UnaryOperator {
PostIncrement,
PostDecrement,
PreIncrement,
PreDecrement,
Address,
Indirection,
Plus,
Minus,
Complement,
Negate,
}
#[derive(Debug, PartialEq, Clone)]
pub struct UnaryOperatorExpression {
pub operator: Node<UnaryOperator>,
pub operand: Box<Node<Expression>>,
}
#[derive(Debug, PartialEq, Clone)]
pub struct CastExpression {
pub type_name: Node<TypeName>,
pub expression: Box<Node<Expression>>,
}
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub enum BinaryOperator {
Index,
Multiply,
Divide,
Modulo,
Plus,
Minus,
ShiftLeft,
ShiftRight,
Less,
Greater,
LessOrEqual,
GreaterOrEqual,
Equals,
NotEquals,
BitwiseAnd,
BitwiseXor,
BitwiseOr,
LogicalAnd,
LogicalOr,
Assign,
AssignMultiply,
AssignDivide,
AssignModulo,
AssignPlus,
AssignMinus,
AssignShiftLeft,
AssignShiftRight,
AssignBitwiseAnd,
AssignBitwiseXor,
AssignBitwiseOr,
}
#[derive(Debug, PartialEq, Clone)]
pub struct BinaryOperatorExpression {
pub operator: Node<BinaryOperator>,
pub lhs: Box<Node<Expression>>,
pub rhs: Box<Node<Expression>>,
}
#[derive(Debug, PartialEq, Clone)]
pub struct ConditionalExpression {
pub condition: Box<Node<Expression>>,
pub then_expression: Box<Node<Expression>>,
pub else_expression: Box<Node<Expression>>,
}
#[derive(Debug, PartialEq, Clone)]
pub struct VaArgExpression {
pub va_list: Box<Node<Expression>>,
pub type_name: Node<TypeName>,
}
#[derive(Debug, PartialEq, Clone)]
pub struct OffsetOfExpression {
pub type_name: Node<TypeName>,
pub designator: Node<OffsetDesignator>,
}
#[derive(Debug, PartialEq, Clone)]
pub struct OffsetDesignator {
pub base: Node<Identifier>,
pub members: Vec<Node<OffsetMember>>,
}
#[derive(Debug, PartialEq, Clone)]
pub enum OffsetMember {
Member(Node<Identifier>),
IndirectMember(Node<Identifier>),
Index(Node<Expression>),
}
#[derive(Debug, PartialEq, Clone)]
pub struct Declaration {
pub specifiers: Vec<Node<DeclarationSpecifier>>,
pub declarators: Vec<Node<InitDeclarator>>,
}
#[derive(Debug, PartialEq, Clone)]
pub enum DeclarationSpecifier {
StorageClass(Node<StorageClassSpecifier>),
TypeSpecifier(Node<TypeSpecifier>),
TypeQualifier(Node<TypeQualifier>),
Function(Node<FunctionSpecifier>),
Alignment(Node<AlignmentSpecifier>),
Extension(Vec<Node<Extension>>),
}
#[derive(Debug, PartialEq, Clone)]
pub struct InitDeclarator {
pub declarator: Node<Declarator>,
pub initializer: Option<Node<Initializer>>,
}
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub enum StorageClassSpecifier {
Typedef,
Extern,
Static,
ThreadLocal,
Auto,
Register,
}
#[derive(Debug, PartialEq, Clone)]
pub enum TypeSpecifier {
Void,
Char,
Short,
Int,
Long,
Float,
Double,
Signed,
Unsigned,
Bool,
Complex,
Atomic(Node<TypeName>),
Struct(Node<StructType>),
Enum(Node<EnumType>),
TypedefName(Node<Identifier>),
TypeOf(Node<TypeOf>),
TS18661Float(TS18661FloatType),
}
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub struct TS18661FloatType {
pub format: TS18661FloatFormat,
pub width: usize,
}
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub enum TS18661FloatFormat {
BinaryInterchange,
BinaryExtended,
DecimalInterchange,
DecimalExtended,
}
#[derive(Debug, PartialEq, Clone)]
pub struct StructType {
pub kind: Node<StructKind>,
pub identifier: Option<Node<Identifier>>,
pub declarations: Option<Vec<Node<StructDeclaration>>>,
}
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub enum StructKind {
Struct,
Union,
}
#[derive(Debug, PartialEq, Clone)]
pub enum StructDeclaration {
Field(Node<StructField>),
StaticAssert(Node<StaticAssert>),
}
#[derive(Debug, PartialEq, Clone)]
pub struct StructField {
pub specifiers: Vec<Node<SpecifierQualifier>>,
pub declarators: Vec<Node<StructDeclarator>>,
}
#[derive(Debug, PartialEq, Clone)]
pub enum SpecifierQualifier {
TypeSpecifier(Node<TypeSpecifier>),
TypeQualifier(Node<TypeQualifier>),
Extension(Vec<Node<Extension>>),
}
#[derive(Debug, PartialEq, Clone)]
pub struct StructDeclarator {
pub declarator: Option<Node<Declarator>>,
pub bit_width: Option<Box<Node<Expression>>>,
}
#[derive(Debug, PartialEq, Clone)]
pub struct EnumType {
pub identifier: Option<Node<Identifier>>,
pub enumerators: Vec<Node<Enumerator>>,
}
#[derive(Debug, PartialEq, Clone)]
pub struct Enumerator {
pub identifier: Node<Identifier>,
pub expression: Option<Box<Node<Expression>>>,
pub extensions: Vec<Node<Extension>>,
}
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub enum TypeQualifier {
Const,
Restrict,
Volatile,
Nonnull,
NullUnspecified,
Nullable,
Atomic,
}
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub enum FunctionSpecifier {
Inline,
Noreturn,
}
#[derive(Debug, PartialEq, Clone)]
pub enum AlignmentSpecifier {
Type(Node<TypeName>),
Constant(Box<Node<Expression>>),
}
#[derive(Debug, PartialEq, Clone)]
pub struct Declarator {
pub kind: Node<DeclaratorKind>,
pub derived: Vec<Node<DerivedDeclarator>>,
pub extensions: Vec<Node<Extension>>,
}
#[derive(Debug, PartialEq, Clone)]
pub enum DeclaratorKind {
Abstract,
Identifier(Node<Identifier>),
Declarator(Box<Node<Declarator>>),
}
#[derive(Debug, PartialEq, Clone)]
pub enum DerivedDeclarator {
Pointer(Vec<Node<PointerQualifier>>),
Array(Node<ArrayDeclarator>),
Function(Node<FunctionDeclarator>),
KRFunction(Vec<Node<Identifier>>),
Block(Vec<Node<PointerQualifier>>),
}
#[derive(Debug, PartialEq, Clone)]
pub struct ArrayDeclarator {
pub qualifiers: Vec<Node<TypeQualifier>>,
pub size: ArraySize,
}
#[derive(Debug, PartialEq, Clone)]
pub struct FunctionDeclarator {
pub parameters: Vec<Node<ParameterDeclaration>>,
pub ellipsis: Ellipsis,
}
#[derive(Debug, PartialEq, Clone)]
pub enum PointerQualifier {
TypeQualifier(Node<TypeQualifier>),
Extension(Vec<Node<Extension>>),
}
#[derive(Debug, PartialEq, Clone)]
pub enum ArraySize {
Unknown,
VariableUnknown,
VariableExpression(Box<Node<Expression>>),
StaticExpression(Box<Node<Expression>>),
}
#[derive(Debug, PartialEq, Clone)]
pub struct ParameterDeclaration {
pub specifiers: Vec<Node<DeclarationSpecifier>>,
pub declarator: Option<Node<Declarator>>,
pub extensions: Vec<Node<Extension>>,
}
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub enum Ellipsis {
Some,
None,
}
#[derive(Debug, PartialEq, Clone)]
pub struct TypeName {
pub specifiers: Vec<Node<SpecifierQualifier>>,
pub declarator: Option<Node<Declarator>>,
}
#[derive(Debug, PartialEq, Clone)]
pub enum Initializer {
Expression(Box<Node<Expression>>),
List(Vec<Node<InitializerListItem>>),
}
#[derive(Debug, PartialEq, Clone)]
pub struct InitializerListItem {
pub designation: Vec<Node<Designator>>,
pub initializer: Box<Node<Initializer>>,
}
#[derive(Debug, PartialEq, Clone)]
pub enum Designator {
Index(Node<Expression>),
Member(Node<Identifier>),
Range(Node<RangeDesignator>),
}
#[derive(Debug, PartialEq, Clone)]
pub struct RangeDesignator {
pub from: Node<Expression>,
pub to: Node<Expression>,
}
#[derive(Debug, PartialEq, Clone)]
pub struct StaticAssert {
pub expression: Box<Node<Expression>>,
pub message: Node<StringLiteral>,
}
#[derive(Debug, PartialEq, Clone)]
pub enum Statement {
Labeled(Node<LabeledStatement>),
Compound(Vec<Node<BlockItem>>),
Expression(Option<Box<Node<Expression>>>),
If(Node<IfStatement>),
Switch(Node<SwitchStatement>),
While(Node<WhileStatement>),
DoWhile(Node<DoWhileStatement>),
For(Node<ForStatement>),
Goto(Node<Identifier>),
Continue,
Break,
Return(Option<Box<Node<Expression>>>),
Asm(Node<AsmStatement>),
}
#[derive(Debug, PartialEq, Clone)]
pub struct LabeledStatement {
pub label: Node<Label>,
pub statement: Box<Node<Statement>>,
}
#[derive(Debug, PartialEq, Clone)]
pub struct IfStatement {
pub condition: Box<Node<Expression>>,
pub then_statement: Box<Node<Statement>>,
pub else_statement: Option<Box<Node<Statement>>>,
}
#[derive(Debug, PartialEq, Clone)]
pub struct SwitchStatement {
pub expression: Box<Node<Expression>>,
pub statement: Box<Node<Statement>>,
}
#[derive(Debug, PartialEq, Clone)]
pub struct WhileStatement {
pub expression: Box<Node<Expression>>,
pub statement: Box<Node<Statement>>,
}
#[derive(Debug, PartialEq, Clone)]
pub struct DoWhileStatement {
pub statement: Box<Node<Statement>>,
pub expression: Box<Node<Expression>>,
}
#[derive(Debug, PartialEq, Clone)]
pub struct ForStatement {
pub initializer: Node<ForInitializer>,
pub condition: Option<Box<Node<Expression>>>,
pub step: Option<Box<Node<Expression>>>,
pub statement: Box<Node<Statement>>,
}
#[derive(Debug, PartialEq, Clone)]
pub enum Label {
Identifier(Node<Identifier>),
Case(Box<Node<Expression>>),
CaseRange(Node<CaseRange>),
Default,
}
#[derive(Debug, PartialEq, Clone)]
pub struct CaseRange {
pub low: Box<Node<Expression>>,
pub high: Box<Node<Expression>>,
}
#[derive(Debug, PartialEq, Clone)]
pub enum ForInitializer {
Empty,
Expression(Box<Node<Expression>>),
Declaration(Node<Declaration>),
StaticAssert(Node<StaticAssert>),
}
#[derive(Debug, PartialEq, Clone)]
pub enum BlockItem {
Declaration(Node<Declaration>),
StaticAssert(Node<StaticAssert>),
Statement(Node<Statement>),
}
#[derive(Debug, PartialEq, Clone)]
pub struct TranslationUnit(pub Vec<Node<ExternalDeclaration>>);
#[derive(Debug, PartialEq, Clone)]
pub enum ExternalDeclaration {
Declaration(Node<Declaration>),
StaticAssert(Node<StaticAssert>),
FunctionDefinition(Node<FunctionDefinition>),
}
#[derive(Debug, PartialEq, Clone)]
pub struct FunctionDefinition {
pub specifiers: Vec<Node<DeclarationSpecifier>>,
pub declarator: Node<Declarator>,
pub declarations: Vec<Node<Declaration>>,
pub statement: Node<Statement>,
}
#[derive(Debug, PartialEq, Clone)]
pub enum Extension {
Attribute(Attribute),
AsmLabel(Node<StringLiteral>),
AvailabilityAttribute(Node<AvailabilityAttribute>),
}
#[derive(Debug, PartialEq, Clone)]
pub struct Attribute {
pub name: Node<String>,
pub arguments: Vec<Node<Expression>>,
}
#[derive(Debug, PartialEq, Clone)]
pub struct AvailabilityAttribute {
pub platform: Node<Identifier>,
pub clauses: Vec<Node<AvailabilityClause>>,
}
#[derive(Debug, PartialEq, Clone)]
pub enum AvailabilityClause {
Introduced(Node<AvailabilityVersion>),
Deprecated(Node<AvailabilityVersion>),
Obsoleted(Node<AvailabilityVersion>),
Unavailable,
Message(Node<StringLiteral>),
Replacement(Node<StringLiteral>),
}
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub struct AvailabilityVersion {
pub major: String,
pub minor: Option<String>,
pub subminor: Option<String>,
}
#[derive(Debug, PartialEq, Clone)]
pub enum AsmStatement {
GnuBasic(Node<StringLiteral>),
GnuExtended(GnuExtendedAsmStatement),
}
#[derive(Debug, PartialEq, Clone)]
pub struct GnuExtendedAsmStatement {
pub qualifier: Option<Node<TypeQualifier>>,
pub template: Node<StringLiteral>,
pub outputs: Vec<Node<GnuAsmOperand>>,
pub inputs: Vec<Node<GnuAsmOperand>>,
pub clobbers: Vec<Node<StringLiteral>>,
}
#[derive(Debug, PartialEq, Clone)]
pub struct GnuAsmOperand {
pub symbolic_name: Option<Node<Identifier>>,
pub constraints: Node<StringLiteral>,
pub variable_name: Node<Expression>,
}
#[derive(Debug, PartialEq, Clone)]
pub enum TypeOf {
Expression(Node<Expression>),
Type(Node<TypeName>),
}