Przeglądaj źródła

Add unchecked block to the ast block

Signed-off-by: Sean Young <sean@mess.org>
Sean Young 4 lat temu
rodzic
commit
75fd40a3bf

+ 5 - 0
src/bin/languageserver/mod.rs

@@ -178,6 +178,11 @@ impl SolangServer {
         ns: &ast::Namespace,
     ) {
         match stmt {
+            ast::Statement::Block { statements, .. } => {
+                for stmt in statements {
+                    SolangServer::construct_stmt(stmt, lookup_tbl, symtab, fnc_map, ns);
+                }
+            }
             ast::Statement::VariableDecl(loc, var_no, _param, expr) => {
                 if let Some(exp) = expr {
                     SolangServer::construct_expr(exp, lookup_tbl, symtab, fnc_map, ns);

+ 4 - 1
src/codegen/external_functions.rs

@@ -125,7 +125,10 @@ fn check_statement(stmt: &Statement, call_list: &mut Vec<usize>) -> bool {
                 e.recurse(call_list, check_expression);
             }
         }
-        Statement::Break(_) | Statement::Continue(_) | Statement::Underscore(_) => (),
+        Statement::Block { .. }
+        | Statement::Break(_)
+        | Statement::Continue(_)
+        | Statement::Underscore(_) => (),
     }
 
     true

+ 15 - 0
src/codegen/statements.rs

@@ -26,6 +26,21 @@ pub fn statement(
     return_override: Option<&Instr>,
 ) {
     match stmt {
+        Statement::Block { statements, .. } => {
+            for stmt in statements {
+                statement(
+                    stmt,
+                    func,
+                    cfg,
+                    contract_no,
+                    ns,
+                    vartab,
+                    loops,
+                    placeholder,
+                    return_override,
+                );
+            }
+        }
         Statement::VariableDecl(loc, pos, _, Some(init)) => {
             if should_remove_variable(pos, func, Some(init)) {
                 let mut params = SideEffectsCheckParameters {

+ 11 - 0
src/sema/ast.rs

@@ -1256,6 +1256,11 @@ impl fmt::Display for CallTy {
 #[derive(Clone, Debug)]
 #[allow(clippy::large_enum_variant)]
 pub enum Statement {
+    Block {
+        loc: pt::Loc,
+        unchecked: bool,
+        statements: Vec<Statement>,
+    },
     VariableDecl(pt::Loc, usize, Parameter, Option<Expression>),
     If(pt::Loc, bool, Expression, Vec<Statement>, Vec<Statement>),
     While(pt::Loc, bool, Expression, Vec<Statement>),
@@ -1317,6 +1322,11 @@ impl Statement {
     pub fn recurse<T>(&self, cx: &mut T, f: fn(stmt: &Statement, ctx: &mut T) -> bool) {
         if f(self, cx) {
             match self {
+                Statement::Block { statements, .. } => {
+                    for stmt in statements {
+                        stmt.recurse(cx, f);
+                    }
+                }
                 Statement::If(_, _, _, then_stmt, else_stmt) => {
                     for stmt in then_stmt {
                         stmt.recurse(cx, f);
@@ -1383,6 +1393,7 @@ impl Statement {
 
     pub fn reachable(&self) -> bool {
         match self {
+            Statement::Block { statements, .. } => statements.iter().all(|s| s.reachable()),
             Statement::Underscore(_)
             | Statement::Destructure(_, _, _)
             | Statement::VariableDecl(_, _, _, _) => true,

+ 3 - 0
src/sema/mutability.rs

@@ -157,6 +157,9 @@ fn check_mutability(func: &Function, ns: &Namespace) -> Vec<Diagnostic> {
 fn recurse_statements(stmts: &[Statement], state: &mut StateCheck) {
     for stmt in stmts.iter() {
         match stmt {
+            Statement::Block { statements, .. } => {
+                recurse_statements(statements, state);
+            }
             Statement::VariableDecl(_, _, _, Some(expr)) => {
                 expr.recurse(state, read_expression);
             }

+ 8 - 0
src/sema/printer.rs

@@ -491,6 +491,14 @@ fn print_statement(stmts: &[Statement], func: &Function, ns: &Namespace) -> Vec<
 
     for stmt in stmts {
         res.push(match stmt {
+            Statement::Block {
+                statements,
+                unchecked,
+                ..
+            } => Tree::Branch(
+                format!("block{}", if *unchecked { " unchecked" } else { "" }),
+                print_statement(statements, func, ns),
+            ),
             Statement::VariableDecl(_, _, p, None) => {
                 Tree::Leaf(format!("declare {} {}", p.ty.to_string(ns), p.name))
             }