diff --git a/src/protocol/ast.rs b/src/protocol/ast.rs index 05d78f666bb6b336eee0c943a2bca7e9467d546e..4a1b4a0f12cb13cb1c2d1b01afebeea4e342142c 100644 --- a/src/protocol/ast.rs +++ b/src/protocol/ast.rs @@ -254,12 +254,6 @@ impl Root { } } -impl SyntaxElement for Root { - fn position(&self) -> InputPosition { - self.position - } -} - #[derive(Debug, Clone)] pub enum Pragma { Version(PragmaVersion), @@ -318,15 +312,6 @@ impl Import { } } -impl SyntaxElement for Import { - fn position(&self) -> InputPosition { - match self { - Import::Module(m) => m.position, - Import::Symbols(m) => m.position - } - } -} - #[derive(Debug, Clone)] pub struct ImportModule { pub this: ImportId, @@ -600,44 +585,52 @@ impl<'a> NamespacedIdentifierIter<'a> { } } -/// TODO: @types Remove the Message -> Byte hack at some point... -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialOrd, Ord)] pub enum ParserTypeVariant { // Basic builtin Message, Bool, - UInt8, Uint16, UInt32, UInt64, + UInt8, UInt16, UInt32, UInt64, SInt8, SInt16, SInt32, SInt64, Character, String, // Literals (need to get concrete builtin type during typechecking) IntegerLiteral, Inferred, - // Complex builtins - Array(ParserTypeId), // array of a type - Input(ParserTypeId), // typed input endpoint of a channel - Output(ParserTypeId), // typed output endpoint of a channel - Symbolic(SymbolicParserType), // symbolic type (definition or polyarg) + // Builtins expecting one subsequent type + Array, + Input, + Output, + // User-defined types + PolymorphicArgument(DefinitionId, usize), // usize = index into polymorphic variables + Definition(DefinitionId, usize), // usize = number of following subtypes } impl ParserTypeVariant { - pub(crate) fn supports_polymorphic_args(&self) -> bool { - use ParserTypeVariant::*; + pub(crate) fn num_embedded(&self) -> usize { match self { - Message | Bool | Byte | Short | Int | Long | String | IntegerLiteral | Inferred => false, - _ => true + x if *x <= ParserTypeVariant::Inferred => 0, + x if *x <= ParserTypeVariant::Output => 1, + ParserTypeVariant::PolymorphicArgument(_, _) => 0, + ParserTypeVariant::Definition(_, num) => num, + _ => { debug_assert!(false); 0 }, } } } +pub struct ParserTypeElement { + // TODO: @cleanup, do we ever need the span of a user-defined type after + // constructing it? + pub full_span: InputSpan, // full span of type, including any polymorphic arguments + pub variant: ParserTypeVariant, +} + /// ParserType is a specification of a type during the parsing phase and initial /// linker/validator phase of the compilation process. These types may be /// (partially) inferred or represent literals (e.g. a integer whose bytesize is /// not yet determined). #[derive(Debug, Clone)] pub struct ParserType { - pub this: ParserTypeId, - pub pos: InputPosition, - pub variant: ParserTypeVariant, + pub elements: Vec } /// SymbolicParserType is the specification of a symbolic type. During the @@ -910,32 +903,17 @@ impl Variable { } } -impl SyntaxElement for Variable { - fn position(&self) -> InputPosition { - match self { - Variable::Parameter(decl) => decl.position(), - Variable::Local(decl) => decl.position(), - } - } -} - /// TODO: Remove distinction between parameter/local and add an enum to indicate /// the distinction between the two #[derive(Debug, Clone)] pub struct Parameter { pub this: ParameterId, - // Phase 1: parser - pub position: InputPosition, - pub parser_type: ParserTypeId, + // Phase 2: parser + pub span: InputSpan, + pub parser_type: ParserType, pub identifier: Identifier, } -impl SyntaxElement for Parameter { - fn position(&self) -> InputPosition { - self.position - } -} - #[derive(Debug, Clone)] pub struct Local { pub this: LocalId, @@ -946,11 +924,6 @@ pub struct Local { // Phase 2: linker pub relative_pos_in_block: u32, } -impl SyntaxElement for Local { - fn position(&self) -> InputPosition { - self.position - } -} #[derive(Debug, Clone)] pub enum Definition { @@ -968,7 +941,13 @@ impl Definition { _ => false } } - pub fn as_struct(&self) -> &StructDefinition { + pub(crate) fn as_struct(&self) -> &StructDefinition { + match self { + Definition::Struct(result) => result, + _ => panic!("Unable to cast 'Definition' to 'StructDefinition'"), + } + } + pub(crate) fn as_struct_mut(&mut self) -> &mut StructDefinition { match self { Definition::Struct(result) => result, _ => panic!("Unable to cast 'Definition' to 'StructDefinition'"), @@ -980,7 +959,13 @@ impl Definition { _ => false, } } - pub fn as_enum(&self) -> &EnumDefinition { + pub(crate) fn as_enum(&self) -> &EnumDefinition { + match self { + Definition::Enum(result) => result, + _ => panic!("Unable to cast 'Definition' to 'EnumDefinition'"), + } + } + pub(crate) fn as_enum_mut(&mut self) -> &mut EnumDefinition { match self { Definition::Enum(result) => result, _ => panic!("Unable to cast 'Definition' to 'EnumDefinition'"), @@ -992,19 +977,31 @@ impl Definition { _ => false, } } - pub fn as_union(&self) -> &UnionDefinition { + pub(crate) fn as_union(&self) -> &UnionDefinition { match self { Definition::Union(result) => result, _ => panic!("Unable to cast 'Definition' to 'UnionDefinition'"), } } + pub(crate) fn as_union_mut(&mut self) -> &mut UnionDefinition { + match self { + Definition::Union(result) => result, + _ => panic!("Unable to cast 'Definition' to 'UnionDefinition'"), + } + } pub fn is_component(&self) -> bool { match self { Definition::Component(_) => true, _ => false, } } - pub fn as_component(&self) -> &ComponentDefinition { + pub(crate) fn as_component(&self) -> &ComponentDefinition { + match self { + Definition::Component(result) => result, + _ => panic!("Unable to cast `Definition` to `Component`"), + } + } + pub(crate) fn as_component_mut(&mut self) -> &mut ComponentDefinition { match self { Definition::Component(result) => result, _ => panic!("Unable to cast `Definition` to `Component`"), @@ -1016,7 +1013,13 @@ impl Definition { _ => false, } } - pub fn as_function(&self) -> &FunctionDefinition { + pub(crate) fn as_function(&self) -> &FunctionDefinition { + match self { + Definition::Function(result) => result, + _ => panic!("Unable to cast `Definition` to `Function`"), + } + } + pub(crate) fn as_function_mut(&mut self) -> &mut FunctionDefinition { match self { Definition::Function(result) => result, _ => panic!("Unable to cast `Definition` to `Function`"), @@ -1048,16 +1051,13 @@ impl Definition { _ => panic!("cannot retrieve body (for EnumDefinition or StructDefinition)") } } -} - -impl SyntaxElement for Definition { - fn position(&self) -> InputPosition { + pub fn poly_vars(&self) -> &Vec { match self { - Definition::Struct(def) => def.position, - Definition::Enum(def) => def.position, - Definition::Union(def) => def.position, - Definition::Component(def) => def.position(), - Definition::Function(def) => def.position(), + Definition::Struct(def) => &def.poly_vars, + Definition::Enum(def) => &def.poly_vars, + Definition::Union(def) => &def.poly_vars, + Definition::Component(def) => &def.poly_vars, + Definition::Function(def) => &def.poly_vars, } } } @@ -1079,23 +1079,25 @@ impl VariableScope for Definition { #[derive(Debug, Clone)] pub struct StructFieldDefinition { + pub span: InputSpan, pub field: Identifier, - pub parser_type: ParserTypeId, + pub parser_type: ParserType, } #[derive(Debug, Clone)] pub struct StructDefinition { pub this: StructDefinitionId, - // Phase 1: parser + // Phase 1: symbol scanning pub span: InputSpan, pub identifier: Identifier, pub poly_vars: Vec, + // Phase 2: parsing pub fields: Vec } impl StructDefinition { - pub(crate) fn new_empty(this: StructDefinitionId, span: InputSpan, identifier: Identifier) -> Self { - Self{ this, span, identifier, poly_vars: Vec::new(), fields: Vec::new() } + pub(crate) fn new_empty(this: StructDefinitionId, span: InputSpan, identifier: Identifier, poly_vars: Vec) -> Self { + Self{ this, span, identifier, poly_vars, fields: Vec::new() } } } @@ -1107,7 +1109,6 @@ pub enum EnumVariantValue { #[derive(Debug, Clone)] pub struct EnumVariantDefinition { - pub position: InputPosition, pub identifier: Identifier, pub value: EnumVariantValue, } @@ -1115,28 +1116,29 @@ pub struct EnumVariantDefinition { #[derive(Debug, Clone)] pub struct EnumDefinition { pub this: EnumDefinitionId, - // Phase 1: parser + // Phase 1: symbol scanning pub span: InputSpan, pub identifier: Identifier, pub poly_vars: Vec, + // Phase 2: parsing pub variants: Vec, } impl EnumDefinition { - pub(crate) fn new_empty(this: EnumDefinitionId, span: InputSpan, identifier: Identifier) -> Self { - Self{ this, span, identifier, poly_vars: Vec::new(), variants: Vec::new() } + pub(crate) fn new_empty(this: EnumDefinitionId, span: InputSpan, identifier: Identifier, poly_vars: Vec) -> Self { + Self{ this, span, identifier, poly_vars, variants: Vec::new() } } } #[derive(Debug, Clone)] pub enum UnionVariantValue { None, - Embedded(Vec), + Embedded(Vec), } #[derive(Debug, Clone)] pub struct UnionVariantDefinition { - pub position: InputPosition, + pub span: InputSpan, pub identifier: Identifier, pub value: UnionVariantValue, } @@ -1144,16 +1146,17 @@ pub struct UnionVariantDefinition { #[derive(Debug, Clone)] pub struct UnionDefinition { pub this: UnionDefinitionId, - // Phase 1: parser + // Phase 1: symbol scanning pub span: InputSpan, pub identifier: Identifier, pub poly_vars: Vec, + // Phase 2: parsing pub variants: Vec, } impl UnionDefinition { - pub(crate) fn new_empty(this: UnionDefinitionId, span: InputSpan, identifier: Identifier) -> Self { - Self{ this, span, identifier, poly_vars: Vec::new(), variants: Vec::new() } + pub(crate) fn new_empty(this: UnionDefinitionId, span: InputSpan, identifier: Identifier, poly_vars: Vec) -> Self { + Self{ this, span, identifier, poly_vars, variants: Vec::new() } } } @@ -1166,62 +1169,50 @@ pub enum ComponentVariant { #[derive(Debug, Clone)] pub struct ComponentDefinition { pub this: ComponentDefinitionId, - // Phase 1: parser + // Phase 1: symbol scanning pub span: InputSpan, pub variant: ComponentVariant, pub identifier: Identifier, pub poly_vars: Vec, + // Phase 2: parsing pub parameters: Vec, pub body: StatementId, } impl ComponentDefinition { - pub(crate) fn new_empty(this: ComponentDefinitionId, span: InputSpan, variant: ComponentVariant, identifier: Identifier) -> Self { + pub(crate) fn new_empty(this: ComponentDefinitionId, span: InputSpan, variant: ComponentVariant, identifier: Identifier, poly_vars: Vec) -> Self { Self{ - this, span, variant, identifier, - poly_vars: Vec::new(), + this, span, variant, identifier, poly_vars, parameters: Vec::new(), body: StatementId::new_invalid() } } } -impl SyntaxElement for ComponentDefinition { - fn position(&self) -> InputPosition { - self.position - } -} - #[derive(Debug, Clone)] pub struct FunctionDefinition { pub this: FunctionDefinitionId, - // Phase 1: parser + // Phase 1: symbol scanning pub span: InputSpan, - pub return_type: ParserTypeId, pub identifier: Identifier, pub poly_vars: Vec, + // Phase 2: parsing + pub return_types: Vec, pub parameters: Vec, pub body: StatementId, } impl FunctionDefinition { - pub(crate) fn new_empty(this: FunctionDefinitionId, span: InputSpan, identifier: Identifier) -> Self { + pub(crate) fn new_empty(this: FunctionDefinitionId, span: InputSpan, identifier: Identifier, poly_vars: Vec) -> Self { Self { - this, span, identifier, + this, span, identifier, poly_vars, return_type: ParserTypeId::new_invalid(), - poly_vars: Vec::new(), parameters: Vec::new(), body: StatementId::new_invalid(), } } } -impl SyntaxElement for FunctionDefinition { - fn position(&self) -> InputPosition { - self.position - } -} - #[derive(Debug, Clone)] pub enum Statement { Block(BlockStatement), @@ -1432,35 +1423,11 @@ impl Statement { } } -impl SyntaxElement for Statement { - fn position(&self) -> InputPosition { - match self { - Statement::Block(stmt) => stmt.position(), - Statement::Local(stmt) => stmt.position(), - Statement::Skip(stmt) => stmt.position(), - Statement::Labeled(stmt) => stmt.position(), - Statement::If(stmt) => stmt.position(), - Statement::EndIf(stmt) => stmt.position(), - Statement::While(stmt) => stmt.position(), - Statement::EndWhile(stmt) => stmt.position(), - Statement::Break(stmt) => stmt.position(), - Statement::Continue(stmt) => stmt.position(), - Statement::Synchronous(stmt) => stmt.position(), - Statement::EndSynchronous(stmt) => stmt.position(), - Statement::Return(stmt) => stmt.position(), - Statement::Assert(stmt) => stmt.position(), - Statement::Goto(stmt) => stmt.position(), - Statement::New(stmt) => stmt.position(), - Statement::Expression(stmt) => stmt.position(), - } - } -} - #[derive(Debug, Clone)] pub struct BlockStatement { pub this: BlockStatementId, // Phase 1: parser - pub position: InputPosition, + pub span: InputSpan, pub statements: Vec, // Phase 2: linker pub parent_scope: Option, @@ -1498,12 +1465,6 @@ impl BlockStatement { } } -impl SyntaxElement for BlockStatement { - fn position(&self) -> InputPosition { - self.position - } -} - impl VariableScope for BlockStatement { fn parent_scope(&self, _h: &Heap) -> Option { self.parent_scope.clone() @@ -1552,15 +1513,6 @@ impl LocalStatement { } } -impl SyntaxElement for LocalStatement { - fn position(&self) -> InputPosition { - match self { - LocalStatement::Memory(stmt) => stmt.position(), - LocalStatement::Channel(stmt) => stmt.position(), - } - } -} - #[derive(Debug, Clone)] pub struct MemoryStatement { pub this: MemoryStatementId, @@ -1571,12 +1523,6 @@ pub struct MemoryStatement { pub next: Option, } -impl SyntaxElement for MemoryStatement { - fn position(&self) -> InputPosition { - self.position - } -} - /// ChannelStatement is the declaration of an input and output port associated /// with the same channel. Note that the polarity of the ports are from the /// point of view of the component. So an output port is something that a @@ -1594,12 +1540,6 @@ pub struct ChannelStatement { pub next: Option, } -impl SyntaxElement for ChannelStatement { - fn position(&self) -> InputPosition { - self.position - } -} - #[derive(Debug, Clone)] pub struct SkipStatement { pub this: SkipStatementId, @@ -1609,12 +1549,6 @@ pub struct SkipStatement { pub next: Option, } -impl SyntaxElement for SkipStatement { - fn position(&self) -> InputPosition { - self.position - } -} - #[derive(Debug, Clone)] pub struct LabeledStatement { pub this: LabeledStatementId, @@ -1627,12 +1561,6 @@ pub struct LabeledStatement { pub in_sync: Option, } -impl SyntaxElement for LabeledStatement { - fn position(&self) -> InputPosition { - self.position - } -} - #[derive(Debug, Clone)] pub struct IfStatement { pub this: IfStatementId, @@ -1645,12 +1573,6 @@ pub struct IfStatement { pub end_if: Option, } -impl SyntaxElement for IfStatement { - fn position(&self) -> InputPosition { - self.position - } -} - #[derive(Debug, Clone)] pub struct EndIfStatement { pub this: EndIfStatementId, @@ -1660,12 +1582,6 @@ pub struct EndIfStatement { pub next: Option, } -impl SyntaxElement for EndIfStatement { - fn position(&self) -> InputPosition { - self.position - } -} - #[derive(Debug, Clone)] pub struct WhileStatement { pub this: WhileStatementId, @@ -1678,12 +1594,6 @@ pub struct WhileStatement { pub in_sync: Option, } -impl SyntaxElement for WhileStatement { - fn position(&self) -> InputPosition { - self.position - } -} - #[derive(Debug, Clone)] pub struct EndWhileStatement { pub this: EndWhileStatementId, @@ -1693,12 +1603,6 @@ pub struct EndWhileStatement { pub next: Option, } -impl SyntaxElement for EndWhileStatement { - fn position(&self) -> InputPosition { - self.position - } -} - #[derive(Debug, Clone)] pub struct BreakStatement { pub this: BreakStatementId, @@ -1709,12 +1613,6 @@ pub struct BreakStatement { pub target: Option, } -impl SyntaxElement for BreakStatement { - fn position(&self) -> InputPosition { - self.position - } -} - #[derive(Debug, Clone)] pub struct ContinueStatement { pub this: ContinueStatementId, @@ -1725,12 +1623,6 @@ pub struct ContinueStatement { pub target: Option, } -impl SyntaxElement for ContinueStatement { - fn position(&self) -> InputPosition { - self.position - } -} - #[derive(Debug, Clone)] pub struct SynchronousStatement { pub this: SynchronousStatementId, @@ -1743,12 +1635,6 @@ pub struct SynchronousStatement { pub parent_scope: Option, } -impl SyntaxElement for SynchronousStatement { - fn position(&self) -> InputPosition { - self.position - } -} - impl VariableScope for SynchronousStatement { fn parent_scope(&self, _h: &Heap) -> Option { self.parent_scope.clone() @@ -1774,12 +1660,6 @@ pub struct EndSynchronousStatement { pub next: Option, } -impl SyntaxElement for EndSynchronousStatement { - fn position(&self) -> InputPosition { - self.position - } -} - #[derive(Debug, Clone)] pub struct ReturnStatement { pub this: ReturnStatementId, @@ -1788,12 +1668,6 @@ pub struct ReturnStatement { pub expression: ExpressionId, } -impl SyntaxElement for ReturnStatement { - fn position(&self) -> InputPosition { - self.position - } -} - #[derive(Debug, Clone)] pub struct AssertStatement { pub this: AssertStatementId, @@ -1804,12 +1678,6 @@ pub struct AssertStatement { pub next: Option, } -impl SyntaxElement for AssertStatement { - fn position(&self) -> InputPosition { - self.position - } -} - #[derive(Debug, Clone)] pub struct GotoStatement { pub this: GotoStatementId, @@ -1820,12 +1688,6 @@ pub struct GotoStatement { pub target: Option, } -impl SyntaxElement for GotoStatement { - fn position(&self) -> InputPosition { - self.position - } -} - #[derive(Debug, Clone)] pub struct NewStatement { pub this: NewStatementId, @@ -1836,12 +1698,6 @@ pub struct NewStatement { pub next: Option, } -impl SyntaxElement for NewStatement { - fn position(&self) -> InputPosition { - self.position - } -} - #[derive(Debug, Clone)] pub struct ExpressionStatement { pub this: ExpressionStatementId, @@ -1852,12 +1708,6 @@ pub struct ExpressionStatement { pub next: Option, } -impl SyntaxElement for ExpressionStatement { - fn position(&self) -> InputPosition { - self.position - } -} - #[derive(Debug, PartialEq, Eq, Clone, Copy)] pub enum ExpressionParent { None, // only set during initial parsing @@ -2043,25 +1893,6 @@ impl Expression { } } -impl SyntaxElement for Expression { - fn position(&self) -> InputPosition { - match self { - Expression::Assignment(expr) => expr.position(), - Expression::Binding(expr) => expr.position, - Expression::Conditional(expr) => expr.position(), - Expression::Binary(expr) => expr.position(), - Expression::Unary(expr) => expr.position(), - Expression::Indexing(expr) => expr.position(), - Expression::Slicing(expr) => expr.position(), - Expression::Select(expr) => expr.position(), - Expression::Array(expr) => expr.position(), - Expression::Literal(expr) => expr.position(), - Expression::Call(expr) => expr.position(), - Expression::Variable(expr) => expr.position(), - } - } -} - #[derive(Debug, Clone)] pub enum AssignmentOperator { Set, @@ -2080,23 +1911,17 @@ pub enum AssignmentOperator { #[derive(Debug, Clone)] pub struct AssignmentExpression { pub this: AssignmentExpressionId, - // Phase 1: parser - pub position: InputPosition, + // Phase 2: parser + pub span: InputSpan, // of the operator pub left: ExpressionId, pub operation: AssignmentOperator, pub right: ExpressionId, - // Phase 2: linker + // Phase 3: linker pub parent: ExpressionParent, - // Phase 3: type checking + // Phase 4: type checking pub concrete_type: ConcreteType, } -impl SyntaxElement for AssignmentExpression { - fn position(&self) -> InputPosition { - self.position - } -} - #[derive(Debug, Clone)] pub struct BindingExpression { pub this: BindingExpressionId, @@ -2114,7 +1939,7 @@ pub struct BindingExpression { pub struct ConditionalExpression { pub this: ConditionalExpressionId, // Phase 1: parser - pub position: InputPosition, + pub span: InputSpan, // of question mark operator pub test: ExpressionId, pub true_expression: ExpressionId, pub false_expression: ExpressionId, @@ -2124,12 +1949,6 @@ pub struct ConditionalExpression { pub concrete_type: ConcreteType, } -impl SyntaxElement for ConditionalExpression { - fn position(&self) -> InputPosition { - self.position - } -} - #[derive(Debug, Clone, PartialEq, Eq)] pub enum BinaryOperator { Concatenate, @@ -2157,7 +1976,7 @@ pub enum BinaryOperator { pub struct BinaryExpression { pub this: BinaryExpressionId, // Phase 1: parser - pub position: InputPosition, + pub span: InputSpan, // of the operator pub left: ExpressionId, pub operation: BinaryOperator, pub right: ExpressionId, @@ -2167,12 +1986,6 @@ pub struct BinaryExpression { pub concrete_type: ConcreteType, } -impl SyntaxElement for BinaryExpression { - fn position(&self) -> InputPosition { - self.position - } -} - #[derive(Debug, Clone, PartialEq, Eq)] pub enum UnaryOperation { Positive, @@ -2189,7 +2002,7 @@ pub enum UnaryOperation { pub struct UnaryExpression { pub this: UnaryExpressionId, // Phase 1: parser - pub position: InputPosition, + pub span: InputSpan, // of the operator pub operation: UnaryOperation, pub expression: ExpressionId, // Phase 2: linker @@ -2198,17 +2011,11 @@ pub struct UnaryExpression { pub concrete_type: ConcreteType, } -impl SyntaxElement for UnaryExpression { - fn position(&self) -> InputPosition { - self.position - } -} - #[derive(Debug, Clone)] pub struct IndexingExpression { pub this: IndexingExpressionId, // Phase 1: parser - pub position: InputPosition, + pub span: InputSpan, pub subject: ExpressionId, pub index: ExpressionId, // Phase 2: linker @@ -2217,17 +2024,11 @@ pub struct IndexingExpression { pub concrete_type: ConcreteType, } -impl SyntaxElement for IndexingExpression { - fn position(&self) -> InputPosition { - self.position - } -} - #[derive(Debug, Clone)] pub struct SlicingExpression { pub this: SlicingExpressionId, // Phase 1: parser - pub position: InputPosition, + pub span: InputSpan, // from '[' to ']'; pub subject: ExpressionId, pub from_index: ExpressionId, pub to_index: ExpressionId, @@ -2237,17 +2038,11 @@ pub struct SlicingExpression { pub concrete_type: ConcreteType, } -impl SyntaxElement for SlicingExpression { - fn position(&self) -> InputPosition { - self.position - } -} - #[derive(Debug, Clone)] pub struct SelectExpression { pub this: SelectExpressionId, // Phase 1: parser - pub position: InputPosition, + pub span: InputSpan, // of the '.' pub subject: ExpressionId, pub field: Field, // Phase 2: linker @@ -2256,17 +2051,11 @@ pub struct SelectExpression { pub concrete_type: ConcreteType, } -impl SyntaxElement for SelectExpression { - fn position(&self) -> InputPosition { - self.position - } -} - #[derive(Debug, Clone)] pub struct ArrayExpression { pub this: ArrayExpressionId, // Phase 1: parser - pub position: InputPosition, + pub span: InputSpan, // from the opening to closing delimiter pub elements: Vec, // Phase 2: linker pub parent: ExpressionParent, @@ -2274,12 +2063,6 @@ pub struct ArrayExpression { pub concrete_type: ConcreteType, } -impl SyntaxElement for ArrayExpression { - fn position(&self) -> InputPosition { - self.position - } -} - // TODO: @tokenizer Symbolic function calls are ambiguous with union literals // that accept embedded values (although the polymorphic arguments are placed // differently). To prevent double work we parse as CallExpression, and during @@ -2298,12 +2081,6 @@ pub struct CallExpression { pub concrete_type: ConcreteType, } -impl SyntaxElement for CallExpression { - fn position(&self) -> InputPosition { - self.position - } -} - #[derive(Debug, Clone)] pub enum Method { Get, @@ -2323,7 +2100,7 @@ pub struct MethodSymbolic { pub struct LiteralExpression { pub this: LiteralExpressionId, // Phase 1: parser - pub position: InputPosition, + pub span: InputSpan, pub value: Literal, // Phase 2: linker pub parent: ExpressionParent, @@ -2331,21 +2108,13 @@ pub struct LiteralExpression { pub concrete_type: ConcreteType, } -impl SyntaxElement for LiteralExpression { - fn position(&self) -> InputPosition { - self.position - } -} - -type LiteralCharacter = Vec; -type LiteralInteger = i64; // TODO: @int_literal - #[derive(Debug, Clone)] pub enum Literal { Null, // message True, False, - Character(LiteralCharacter), + Character(char), + String(StringRef<'static>), Integer(LiteralInteger), Struct(LiteralStruct), Enum(LiteralEnum), @@ -2386,6 +2155,12 @@ impl Literal { } } +#[derive(Debug, Clone)] +pub struct LiteralInteger { + pub(crate) unsigned_value: u64, + pub(crate) negated: bool, // for constant expression evaluation, TODO +} + #[derive(Debug, Clone)] pub struct LiteralStructField { // Phase 1: parser @@ -2405,10 +2180,6 @@ pub struct LiteralStruct { pub(crate) definition: Option } -// TODO: @tokenizer Enum literals are ambiguous with union literals that do not -// accept embedded values. To prevent double work for now we parse as a -// LiteralEnum, and during validation we may transform the expression into a -// union literal. #[derive(Debug, Clone)] pub struct LiteralEnum { // Phase 1: parser @@ -2441,10 +2212,4 @@ pub struct VariableExpression { pub parent: ExpressionParent, // Phase 3: type checking pub concrete_type: ConcreteType, -} - -impl SyntaxElement for VariableExpression { - fn position(&self) -> InputPosition { - self.position - } -} +} \ No newline at end of file