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

Berry coc parser keeps order of variables #21542

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file.

### Changed
- TCP bridge increased baudrate selection (#21528)
- Berry coc parser keeps order of variables

### Fixed
- uDisplay Parallel display on Core3 (#21529)
Expand Down
25 changes: 13 additions & 12 deletions lib/libesp32/berry/tools/coc/hash_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ def __init__(self, map):
self.bucket = []

self.resize(2)
var_count = 0
# replace any 'var' by its slot number
for (key, value) in map.items():
if value == "var":
map[key] = var_count
var_count += 1

for key in sorted(map.keys()):
self.insert(key, map[key])

Expand Down Expand Up @@ -115,35 +122,29 @@ def insert(self, key, value):
# Compute entries in the hash for modules or classes
#################################################################################
# return a list (entiry, var_count)
def entry_modify(self, ent, var_count):
def entry_modify(self, ent):
ent.key = escape_operator(ent.key)
if ent.value == "var":
ent.value = "be_const_var(" + str(var_count) + ")"
var_count += 1
if isinstance(ent.value, int):
ent.value = "be_const_var(" + str(ent.value) + ")"
else:
ent.value = "be_const_" + ent.value
return (ent, var_count)
return ent

# generate the final map
def entry_list(self):
l = []
var_count = 0

self.resize(self.count)
for it in self.bucket:
(ent, var_count) = self.entry_modify(it, var_count)
# print(f"ent={ent} var_count={var_count}")
# # ex: ent=<entry object; key='arg', value='be_const_func(w_webserver_arg)', next=-1> var_count=0
# # ex: ent=<entry object; key='check_privileged_access2', value='be_const_func(w_webserver_check_privileged_access_ntv, "b", "")', next=-1> var_count=0
l.append(ent)
l.append(self.entry_modify(it))
return l

def var_count(self):
count = 0

self.resize(self.count)
for it in self.bucket:
if it.value == "var": count += 1
if isinstance(it.value, int): count += 1
return count

if __name__ == '__main__':
Expand Down