Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(AST): introduce AstVisitor trait #1231

Merged
merged 11 commits into from
Jun 12, 2024
4 changes: 0 additions & 4 deletions compiler/plc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,6 @@ pub enum AstStatement {
DefaultValue(DefaultValue),
// Literals
Literal(AstLiteral),
CastStatement(CastStatement),
MultipliedStatement(MultipliedStatement),
// Expressions
ReferenceExpr(ReferenceExpr),
Expand Down Expand Up @@ -735,9 +734,6 @@ impl Debug for AstNode {
}
AstStatement::ContinueStatement(..) => f.debug_struct("ContinueStatement").finish(),
AstStatement::ExitStatement(..) => f.debug_struct("ExitStatement").finish(),
AstStatement::CastStatement(CastStatement { target, type_name }) => {
f.debug_struct("CastStatement").field("type_name", type_name).field("target", target).finish()
}
AstStatement::ReferenceExpr(ReferenceExpr { access, base }) => {
f.debug_struct("ReferenceExpr").field("kind", access).field("base", base).finish()
}
Expand Down
1 change: 1 addition & 0 deletions compiler/plc_ast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ pub mod control_statements;
pub mod literals;
mod pre_processor;
pub mod provider;
pub mod visitor;
714 changes: 714 additions & 0 deletions compiler/plc_ast/src/visitor.rs

Large diffs are not rendered by default.

14 changes: 0 additions & 14 deletions src/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -846,20 +846,6 @@ fn generate_variable_length_array_bound_function<'ink>(
let offset = if is_lower { (value - 1) as u64 * 2 } else { (value - 1) as u64 * 2 + 1 };
llvm.i32_type().const_int(offset, false)
}
AstStatement::CastStatement(data) => {
let ExpressionValue::RValue(value) = generator.generate_expression_value(&data.target)? else {
unreachable!()
};

if !value.is_int_value() {
return Err(Diagnostic::codegen_error(
format!("Expected INT value, found {}", value.get_type()),
location,
));
};

value.into_int_value()
}
// e.g. LOWER_BOUND(arr, idx + 3)
_ => {
let expression_value = generator.generate_expression(params[1])?;
Expand Down
1 change: 0 additions & 1 deletion src/codegen/generators/expression_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1751,7 +1751,6 @@ impl<'ink, 'b> ExpressionCodeGenerator<'ink, 'b> {
}
// if there is just one assignment, this may be an struct-initialization (TODO this is not very elegant :-/ )
AstStatement::Assignment { .. } => self.generate_literal_struct(literal_statement),
AstStatement::CastStatement(data) => self.generate_expression_value(&data.target),
_ => Err(cannot_generate_literal()),
}
}
Expand Down
1 change: 1 addition & 0 deletions src/parser/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use plc_ast::{
use plc_source::source_location::SourceLocation;

// Copyright (c) 2020 Ghaith Hachem and Mathias Rieder
mod ast_visitor_tests;
mod class_parser_tests;
mod container_parser_tests;
mod control_parser_tests;
Expand Down
Loading
Loading