From b34478004aebb65f52348339a8b77a87ffa4d634 Mon Sep 17 00:00:00 2001 From: mertcandav Date: Mon, 8 Apr 2024 19:00:10 +0300 Subject: [PATCH] sema: minor optimizations --- std/jule/README.md | 2 ++ std/jule/sema/sema.jule | 67 +++++++++++------------------------------ 2 files changed, 20 insertions(+), 49 deletions(-) diff --git a/std/jule/README.md b/std/jule/README.md index 9364f027a..2ef7e2f0f 100644 --- a/std/jule/README.md +++ b/std/jule/README.md @@ -46,3 +46,5 @@ For example: - **(7.1)** When analyzing structures, operator overload methods must first be made ready for control and qualified. If an operator tries to use overloading, one of whose construction methods has not yet been analyzed, it will cause analysis errors. - **(7.2)** Operators must be checkec and assigned to structures before analysis of methods and others. Because problems can occur if you analysis operators structure by structure. Semantic will analyze structures file by file. Therefore if an operator tries to use overloading from other file, one of whose construction methods has not yet been assigned, it will cause analysis errors. + +- **(8)** Check `enum` declarations first before using them or any using possibility appears. Enum fields should be evaluated before evaluate algorithms executed. Otherwise, probably program will panic because of unevaluated enum field(s) when tried to use. \ No newline at end of file diff --git a/std/jule/sema/sema.jule b/std/jule/sema/sema.jule index 5d53cd502..4d1fd4740 100644 --- a/std/jule/sema/sema.jule +++ b/std/jule/sema/sema.jule @@ -1653,7 +1653,6 @@ impl Sema { self.check_directives(s.directives, s) - s.sema = self match { | !self.check_decl_generics(s.generics): | !self.check_struct_fields(s): @@ -1788,37 +1787,16 @@ impl Sema { fn check_package_decls(mut &self) { for (_, mut f) in self.files { self.set_current_file(f) - if !self.check_type_alias_decls() { - ret - } - } - - for (_, mut f) in self.files { - self.set_current_file(f) - if !self.check_trait_decls() { - ret - } - } - - for (_, mut f) in self.files { - self.set_current_file(f) - if !self.check_global_decls() { - ret - } - } - - for (_, mut f) in self.files { - self.set_current_file(f) - if !self.check_fn_decls() { - ret - } - } - - for (_, mut f) in self.files { - self.set_current_file(f) - if !self.check_struct_decls() { - ret + match { + | !self.check_type_alias_decls(): + | !self.check_trait_decls(): + | !self.check_global_decls(): + | !self.check_fn_decls(): + | !self.check_struct_decls(): + |: + continue } + ret } } @@ -2122,7 +2100,7 @@ impl Sema { } } - fn check_type_struct_operators(mut &self, mut &s: &Struct) { + fn precheck_struct_type(mut &self, mut &s: &Struct) { if s.cpp_linked { ret } @@ -2142,9 +2120,9 @@ impl Sema { self.check_struct_ins_operators(s.instances[0]) } - fn check_struct_types_operators(mut &self) { + fn precheck_struct_types(mut &self) { for (_, mut s) in self.file.structs { - self.check_type_struct_operators(s) + self.precheck_struct_type(s) } } @@ -2289,29 +2267,18 @@ impl Sema { // Checks all types of all package files. // Breaks checking if checked file failed. fn check_package_types(mut &self) { - for (_, mut f) in self.files { - self.set_current_file(f) - self.check_global_types() - } - for (_, mut f) in self.files { self.set_current_file(f) self.precheck_fn_types() + // Check structures first, see developer reference (7). + // Check operators first, see developer reference (7.1), and (7.2). + self.precheck_struct_types() } - // Check structures first, see developer reference (7). - // Check operators first, see developer reference (7.1), and (7.2). - for (_, mut f) in self.files { - self.set_current_file(f) - self.check_struct_types_operators() - } for (_, mut f) in self.files { self.set_current_file(f) + self.check_global_types() self.check_struct_types() - } - - for (_, mut f) in self.files { - self.set_current_file(f) self.check_fn_types() } } @@ -2342,6 +2309,8 @@ impl Sema { ret } + // Check enums here. + // See developer reference (8). self.check_enums() // Break checking if enums has error. if self.errors.len != 0 {