|
| 1 | +use super::{AbstractDeclarator, SpecifierQualifierList}; |
| 2 | +use crate::{ |
| 3 | + c::{ |
| 4 | + encoding::Encoding, |
| 5 | + token::{FloatSuffix, Integer}, |
| 6 | + }, |
| 7 | + source_files::Source, |
| 8 | +}; |
| 9 | + |
| 10 | +#[derive(Clone, Debug)] |
| 11 | +pub struct ConstExpr { |
| 12 | + pub value: Expr, |
| 13 | +} |
| 14 | + |
| 15 | +#[derive(Clone, Debug)] |
| 16 | +pub struct Expr { |
| 17 | + pub kind: ExprKind, |
| 18 | + pub source: Source, |
| 19 | +} |
| 20 | + |
| 21 | +#[derive(Clone, Debug)] |
| 22 | +pub enum ExprKind { |
| 23 | + Integer(Integer), |
| 24 | + Float(f64, FloatSuffix), |
| 25 | + StringLiteral(Encoding, String), |
| 26 | + Bool(bool), |
| 27 | + Nullptr, |
| 28 | + Character(Encoding, String), |
| 29 | + Compound(Vec<Expr>), |
| 30 | + BinaryOperation(Box<BinaryOperation>), |
| 31 | + Ternary(Box<Ternary>), |
| 32 | + Cast(Box<Cast>), |
| 33 | + Subscript(Box<Subscript>), |
| 34 | + Field(Box<Field>), |
| 35 | + PostIncrement(Box<Expr>), |
| 36 | + PostDecrement(Box<Expr>), |
| 37 | + Identifier(String), |
| 38 | + EnumConstant(String, Integer), |
| 39 | + CompoundLiteral(Box<CompoundLiteral>), |
| 40 | + AddressOf(Box<Expr>), |
| 41 | + Dereference(Box<Expr>), |
| 42 | + Negate(Box<Expr>), |
| 43 | + BitComplement(Box<Expr>), |
| 44 | + Not(Box<Expr>), |
| 45 | + Call(Box<Expr>, Vec<Expr>), |
| 46 | +} |
| 47 | + |
| 48 | +impl ExprKind { |
| 49 | + pub fn at(self, source: Source) -> Expr { |
| 50 | + Expr { kind: self, source } |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +#[derive(Clone, Debug)] |
| 55 | +pub enum BinaryOperator { |
| 56 | + LogicalOr, |
| 57 | + LogicalAnd, |
| 58 | + InclusiveOr, |
| 59 | + ExclusiveOr, |
| 60 | + BitwiseAnd, |
| 61 | + Equals, |
| 62 | + NotEquals, |
| 63 | + LessThan, |
| 64 | + GreaterThan, |
| 65 | + LessThanEq, |
| 66 | + GreaterThanEq, |
| 67 | + LeftShift, |
| 68 | + RightShift, |
| 69 | + Add, |
| 70 | + Subtract, |
| 71 | + Multiply, |
| 72 | + Divide, |
| 73 | + Modulus, |
| 74 | + Assign, |
| 75 | + AddAssign, |
| 76 | + SubtractAssign, |
| 77 | + MultiplyAssign, |
| 78 | + DivideAssign, |
| 79 | + ModulusAssign, |
| 80 | + LeftShiftAssign, |
| 81 | + RightShiftAssign, |
| 82 | + BitAndAssign, |
| 83 | + BitXorAssign, |
| 84 | + BitOrAssign, |
| 85 | +} |
| 86 | + |
| 87 | +#[derive(Clone, Debug)] |
| 88 | +pub struct BinaryOperation { |
| 89 | + pub operator: BinaryOperator, |
| 90 | + pub left: Expr, |
| 91 | + pub right: Expr, |
| 92 | +} |
| 93 | + |
| 94 | +#[derive(Clone, Debug)] |
| 95 | +pub struct Ternary { |
| 96 | + pub condition: Expr, |
| 97 | + pub when_true: Expr, |
| 98 | + pub when_false: Expr, |
| 99 | +} |
| 100 | + |
| 101 | +#[derive(Clone, Debug)] |
| 102 | +pub struct Cast { |
| 103 | + pub specializer_qualifiers: SpecifierQualifierList, |
| 104 | + pub abstract_declarator: Option<AbstractDeclarator>, |
| 105 | + pub inner: Expr, |
| 106 | +} |
| 107 | + |
| 108 | +#[derive(Clone, Debug)] |
| 109 | +pub struct Subscript { |
| 110 | + pub subject: Expr, |
| 111 | + pub subscript: Expr, |
| 112 | + pub source: Source, |
| 113 | +} |
| 114 | + |
| 115 | +#[derive(Clone, Debug)] |
| 116 | +pub struct Field { |
| 117 | + pub subject: Expr, |
| 118 | + pub field: String, |
| 119 | + pub source: Source, |
| 120 | + pub is_pointer: bool, |
| 121 | +} |
| 122 | + |
| 123 | +#[derive(Clone, Debug)] |
| 124 | +pub struct Caster { |
| 125 | + pub specializer_qualifiers: SpecifierQualifierList, |
| 126 | + pub abstract_declarator: Option<AbstractDeclarator>, |
| 127 | + pub source: Source, |
| 128 | +} |
| 129 | + |
| 130 | +#[derive(Clone, Debug)] |
| 131 | +pub struct CompoundLiteral { |
| 132 | + pub caster: Caster, |
| 133 | + pub braced_initializer: BracedInitializer, |
| 134 | +} |
| 135 | + |
| 136 | +#[derive(Clone, Debug)] |
| 137 | +pub struct BracedInitializer { |
| 138 | + pub designated_initializers: Vec<DesignatedInitializer>, |
| 139 | +} |
| 140 | + |
| 141 | +#[derive(Clone, Debug)] |
| 142 | +pub struct DesignatedInitializer { |
| 143 | + pub designation: Option<Designation>, |
| 144 | + pub initializer: Initializer, |
| 145 | +} |
| 146 | + |
| 147 | +#[derive(Clone, Debug)] |
| 148 | +pub enum Initializer { |
| 149 | + Expression(Expr), |
| 150 | + BracedInitializer(BracedInitializer), |
| 151 | +} |
| 152 | + |
| 153 | +#[derive(Clone, Debug)] |
| 154 | +pub struct Designation { |
| 155 | + pub path: Vec<Designator>, |
| 156 | +} |
| 157 | + |
| 158 | +#[derive(Clone, Debug)] |
| 159 | +pub enum Designator { |
| 160 | + Subscript(ConstExpr), |
| 161 | + Field(String), |
| 162 | +} |
0 commit comments