Skip to content

Commit

Permalink
Add callbacks to record parse progress
Browse files Browse the repository at this point in the history
  • Loading branch information
florianschanda committed Sep 27, 2023
1 parent de2750e commit 0c33dec
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ generated in the following situations:

## Changelog


### 1.2.2-dev


* [API] Add callbacks to the
[Source_Manager](https://bmw-software-engineering.github.io/trlc/manual/infrastructure.html#trlc.trlc.Source_Manager)
to notify clients of the parse progress.

### 1.2.1

Expand Down
38 changes: 38 additions & 0 deletions trlc/trlc.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,26 @@ def __init__(self, mh,
self.exclude_patterns = []
self.common_root = None

self.progress_current = 0
self.progress_final = 0

def callback_parse_begin(self):
pass

def callback_parse_progress(self, progress):
assert isinstance(progress, int)

def callback_parse_end(self):
pass

def signal_progress(self):
self.progress_current += 1
if self.progress_final:
progress = (self.progress_current * 100) // self.progress_final
else:
progress = 100
self.callback_parse_progress(min(progress, 100))

def cross_file_reference(self, location):
assert isinstance(location, Location)

Expand Down Expand Up @@ -190,6 +210,9 @@ def register_file(self, file_name, file_content=None):
except TRLC_Error:
ok = False

if ok:
self.progress_final += 1

return ok

def register_directory(self, dir_name):
Expand Down Expand Up @@ -315,6 +338,7 @@ def parse_rsl_files(self):
try:
parser = self.rsl_files[self.packages[pkg]["file"]]
ok &= parser.parse_rsl_file()
self.signal_progress()
except TRLC_Error:
ok = False
processed_packages.add(pkg)
Expand All @@ -329,6 +353,7 @@ def parse_check_files(self):
for name in sorted(self.check_files):
try:
ok &= self.check_files[name].parse_check_file()
self.signal_progress()
except TRLC_Error:
ok = False
return ok
Expand All @@ -354,6 +379,7 @@ def parse_trlc_files(self):
continue
try:
ok &= self.trlc_files[name].parse_trlc_file()
self.signal_progress()
except TRLC_Error:
ok = False

Expand Down Expand Up @@ -398,18 +424,24 @@ def process(self):
"""
# lobster-trace: LRM.File_Parsing_Order

# Notify callback
self.callback_parse_begin()
self.progress_current = 0

# Parse RSL files (topologically sorted, in order to deal with
# dependencies)
ok = self.parse_rsl_files()

if not self.error_recovery and not ok:
self.callback_parse_end()
return None

# Parse check files. At this point we cannot introduce anything
# new in terms of packages.
ok &= self.parse_check_files()

if not self.error_recovery and not ok:
self.callback_parse_end()
return None

# Perform sanity checks (enabled by default). We only do this
Expand All @@ -419,6 +451,7 @@ def process(self):

# Stop here if we're not processing TRLC files.
if not self.parse_trlc:
self.callback_parse_end()
if ok:
return self.stab
else:
Expand All @@ -428,21 +461,26 @@ def process(self):
# resolution happens here, with the notable exception of resolving
# record references (as we can have circularity here).
if not self.parse_trlc_files():
self.callback_parse_end()
return None

# Resolve record reference names and do the missing semantic
# analysis.
# lobster-trace: LRM.File_Parsing_References
if not self.resolve_record_references():
self.callback_parse_end()
return None

if not ok:
self.callback_parse_end()
return None

# Finally, apply user defined checks
if not self.perform_checks():
self.callback_parse_end()
return None

self.callback_parse_end()
return self.stab


Expand Down

0 comments on commit 0c33dec

Please sign in to comment.