Commit 9f341513 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(defined_fields): New variable.

(undefined_fields): New variable.
(prot_a_struct.add_field): Handle defined_fields and undefined_fields.
(prot_a_bitstring.add_field): Ditto.
(lexer.toplevel_bye): Check for undefined fields.
(lexer.toplevel_field): New method.
parent f61a33ba
...@@ -7,6 +7,17 @@ import types ...@@ -7,6 +7,17 @@ import types
# A mapping from type names (as strings) to prot_a_* objects. # A mapping from type names (as strings) to prot_a_* objects.
defined_types = {} defined_types = {}
# All fields that have been seen so far. Initialized with some
# built-in fields.
defined_fields = {
'error-code': None,
'error-status': None,
'ref-no': None,
'reply-data': None,
}
# Fields seen in @field{} but not yet defined.
undefined_fields = {}
def number_suffixed(s, base): def number_suffixed(s, base):
if not s.startswith(base): if not s.startswith(base):
return 0 return 0
...@@ -76,6 +87,9 @@ class prot_a_struct(prot_a_type): ...@@ -76,6 +87,9 @@ class prot_a_struct(prot_a_type):
o = (field_name, type_name, is_array) o = (field_name, type_name, is_array)
self.__used_names[field_name] = o self.__used_names[field_name] = o
self.__fields.append(o) self.__fields.append(o)
defined_fields[field_name] = None
if undefined_fields.has_key(field_name):
del undefined_fields[field_name]
return None return None
def use_recurse(self): def use_recurse(self):
...@@ -91,6 +105,9 @@ class prot_a_bitstring(prot_a_type): ...@@ -91,6 +105,9 @@ class prot_a_bitstring(prot_a_type):
if self.__bits.has_key(field_name): if self.__bits.has_key(field_name):
return "bit ``%s'' used twice" % field_name return "bit ``%s'' used twice" % field_name
self.__bits[field_name] = None self.__bits[field_name] = None
defined_fields[field_name] = None
if undefined_fields.has_key(field_name):
del undefined_fields[field_name]
def check_implemented(self, name, implemented_fields): def check_implemented(self, name, implemented_fields):
res = [] res = []
...@@ -404,7 +421,6 @@ class lexer: ...@@ -404,7 +421,6 @@ class lexer:
toplevel_errorcode = ignore toplevel_errorcode = ignore
toplevel_misc = ignore toplevel_misc = ignore
toplevel_type = ignore toplevel_type = ignore
toplevel_field = ignore
toplevel_dfn = ignore toplevel_dfn = ignore
toplevel_conftype = ignore toplevel_conftype = ignore
toplevel_command = ignore toplevel_command = ignore
...@@ -661,6 +677,11 @@ class lexer: ...@@ -661,6 +677,11 @@ class lexer:
self.error(self.__reader.line_no(), emsg) self.error(self.__reader.line_no(), emsg)
# Check fields.
for (field, lines) in undefined_fields.items():
for lin in lines:
self.error(lin, "undefined field ``%s'' referenced" % field)
self.__reader.check_paren_null() self.__reader.check_paren_null()
# This is the normal exit of the program. It isn't nice to hide # This is the normal exit of the program. It isn't nice to hide
...@@ -1109,6 +1130,12 @@ class lexer: ...@@ -1109,6 +1130,12 @@ class lexer:
return return
self.__args[argname] = [self.__reader.line_no(), 0] self.__args[argname] = [self.__reader.line_no(), 0]
def toplevel_field(self, arg, line_no):
if not defined_fields.has_key(arg):
if not undefined_fields.has_key(arg):
undefined_fields[arg] = []
undefined_fields[arg].append(line_no)
def __unget_token(self, token): def __unget_token(self, token):
self.__tokens.insert(0, token) self.__tokens.insert(0, token)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment