Skip to content

Commit

Permalink
sema: minor optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Apr 8, 2024
1 parent 55364d4 commit b344780
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 49 deletions.
2 changes: 2 additions & 0 deletions std/jule/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
67 changes: 18 additions & 49 deletions std/jule/sema/sema.jule
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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
}
Expand All @@ -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)
}
}

Expand Down Expand Up @@ -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()
}
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit b344780

Please sign in to comment.