mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-04 05:05:19 +08:00
events parser: make '/* EVENT' optional, but prevent 'using namespace events'
Allows for more compact code for very simple events w/o description
This commit is contained in:
@@ -89,6 +89,7 @@ class SourceParser(object):
|
|||||||
|
|
||||||
re_split_lines = re.compile(r'[\r\n]+')
|
re_split_lines = re.compile(r'[\r\n]+')
|
||||||
re_comment_start = re.compile(r'^\/\*\s*EVENT$')
|
re_comment_start = re.compile(r'^\/\*\s*EVENT$')
|
||||||
|
re_events_send = re.compile(r'^events::send[<\(]')
|
||||||
re_comment_content = re.compile(r'^\*\s*(.*)')
|
re_comment_content = re.compile(r'^\*\s*(.*)')
|
||||||
re_comment_tag = re.compile(r'^@([a-zA-Z][a-zA-Z0-9_]*):?\s*(.*)')
|
re_comment_tag = re.compile(r'^@([a-zA-Z][a-zA-Z0-9_]*):?\s*(.*)')
|
||||||
re_comment_end = re.compile(r'(.*?)\s*\*\/$')
|
re_comment_end = re.compile(r'(.*?)\s*\*\/$')
|
||||||
@@ -142,6 +143,10 @@ class SourceParser(object):
|
|||||||
# Ignore empty lines
|
# Ignore empty lines
|
||||||
if line == "":
|
if line == "":
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
assert not line.startswith("using namespace events;"), "Avoid 'using namespace events;', as it prevents proper events extraction"
|
||||||
|
|
||||||
|
# Check for '/* EVENT'
|
||||||
if self.re_comment_start.match(line):
|
if self.re_comment_start.match(line):
|
||||||
state = "parse-comments"
|
state = "parse-comments"
|
||||||
event = Event()
|
event = Event()
|
||||||
@@ -149,8 +154,20 @@ class SourceParser(object):
|
|||||||
current_value = None
|
current_value = None
|
||||||
current_code = ""
|
current_code = ""
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# Check for events::send (allow '/* EVENT' to be optional)
|
||||||
|
if state is None and self.re_events_send.match(line):
|
||||||
|
state = "parse-command"
|
||||||
|
event = Event()
|
||||||
|
current_tag = None
|
||||||
|
current_value = None
|
||||||
|
current_code = ""
|
||||||
|
|
||||||
if state is None:
|
if state is None:
|
||||||
|
assert 'events::ID(' not in line or line.startswith('//'), \
|
||||||
|
"unmatched 'events::ID(' found in line '{:}'".format(line)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if state == "parse-command":
|
if state == "parse-command":
|
||||||
current_code += line
|
current_code += line
|
||||||
m = self.re_code_end.search(line)
|
m = self.re_code_end.search(line)
|
||||||
@@ -185,11 +202,19 @@ class SourceParser(object):
|
|||||||
event.arguments[i] = (arg_type, arg_name)
|
event.arguments[i] = (arg_type, arg_name)
|
||||||
#print("method: {}, args: {}, template args: {}".format(call, args, event.arguments))
|
#print("method: {}, args: {}, template args: {}".format(call, args, event.arguments))
|
||||||
|
|
||||||
|
ignore_event = False
|
||||||
|
|
||||||
# extract function arguments
|
# extract function arguments
|
||||||
args_split = self._parse_arguments(args)
|
args_split = self._parse_arguments(args)
|
||||||
if call == "events::send" or call == "send":
|
if call == "events::send" or call == "send":
|
||||||
|
if len(args_split) == 1:
|
||||||
|
# This is a send call for a generated event
|
||||||
|
ignore_event = True
|
||||||
|
else:
|
||||||
assert len(args_split) == num_args + 3, \
|
assert len(args_split) == num_args + 3, \
|
||||||
"Unexpected Number of arguments for: {:}, {:}".format(args_split, num_args)
|
"Unexpected Number of arguments for: {:}, " \
|
||||||
|
"num template args: {:} (missing template args?)" \
|
||||||
|
.format(args_split, num_args)
|
||||||
m = self.re_event_id.search(args_split[0])
|
m = self.re_event_id.search(args_split[0])
|
||||||
if m:
|
if m:
|
||||||
_, event_name = m.group(1, 2)
|
_, event_name = m.group(1, 2)
|
||||||
@@ -216,6 +241,7 @@ class SourceParser(object):
|
|||||||
else:
|
else:
|
||||||
raise Exception("unknown event method call: {}, args: {}".format(call, args))
|
raise Exception("unknown event method call: {}, args: {}".format(call, args))
|
||||||
|
|
||||||
|
if not ignore_event:
|
||||||
event.validate()
|
event.validate()
|
||||||
|
|
||||||
# insert
|
# insert
|
||||||
@@ -225,7 +251,7 @@ class SourceParser(object):
|
|||||||
|
|
||||||
state = None
|
state = None
|
||||||
|
|
||||||
else:
|
else: # parse-comments
|
||||||
m = self.re_comment_end.search(line)
|
m = self.re_comment_end.search(line)
|
||||||
if m:
|
if m:
|
||||||
line = m.group(1)
|
line = m.group(1)
|
||||||
|
|||||||
Reference in New Issue
Block a user