def _add_class(self, the_type): logger.info(' Parser : Adding class %s', the_type.name) new_class = find_or_add_class(the_type.name) new_class.in_file = self._current_file if new_class not in self._current_file.members: self._current_file.members.append(new_class) new_class.setup_from(the_type)
def parse_all_units(): parser = SGPasParser() lib_file = find_or_add_file('SGSDK', 'SGSDK', './sgsdk.pas') # Build up a cache of the unit files (excludes sgsdk.pas) files = [find_or_add_file(*args) for args in all_units] # Parse each unit file (excluding sgsdk.pas) for a_file in files: parser.parse(a_file) # Create the "lib" class, and checks all its methods to ensure that the # method arguments, and the called-by parameters, match. find_or_add_class('lib').check_methods() # Tell the lib file about each of the known (or discovered) unit files lib_file.uses.extend([f for f in all_files().values() if f != lib_file]) lib_file.members.append(find_or_add_class('lib')) post_parse_process(lib_file)
def parse_all_units(): parser = SGPasParser() lib_file = find_or_add_file('SGSDK','SGSDK','./sgsdk.pas') # Build up a cache of the unit files (excludes sgsdk.pas) files = [ find_or_add_file(*args) for args in all_units ] # Parse each unit file (excluding sgsdk.pas) for a_file in files: parser.parse(a_file) # Create the "lib" class, and checks all its methods to ensure that the # method arguments, and the called-by parameters, match. find_or_add_class('lib').check_methods() # Tell the lib file about each of the known (or discovered) unit files lib_file.uses.extend([ f for f in all_files().values() if f != lib_file ] ) lib_file.members.append(find_or_add_class('lib')) post_parse_process(lib_file)
def _setup_lib_method(self, uname): the_lib = find_or_add_class('lib') method = the_lib.find_method(uname, self._current_file.name) if method == None: method = SGMethod(uname) method.in_file = self._current_file method.in_class = the_lib method.in_class.add_member(method) self._add_attribute('method_called', method) return method
def _create_model_element(self, kind): name = self._get_attribute('name') if kind == SGCodeModule: result = find_or_add_class(name) if not result in self._current_file.members: self._current_file.members.append(result) result.file_line_details = self._tokeniser.line_details() result.meta_comment_line_details = self._tokeniser.meta_comment_line_details() elif kind == SGType: assert False #result = find_or_add_type(name) else: result = kind(name) result.file_line_details = self._tokeniser.line_details() result.meta_comment_line_details = self._tokeniser.meta_comment_line_details() result.in_file = self._current_file logger.debug('Parser : Creating model element: %s with kind:%s', name, kind) return result
def _create_model_element(self, kind): name = self._get_attribute('name') if kind == SGCodeModule: result = find_or_add_class(name) if not result in self._current_file.members: self._current_file.members.append(result) result.file_line_details = self._tokeniser.line_details() result.meta_comment_line_details = self._tokeniser.meta_comment_line_details( ) elif kind == SGType: assert False #result = find_or_add_type(name) else: result = kind(name) result.file_line_details = self._tokeniser.line_details() result.meta_comment_line_details = self._tokeniser.meta_comment_line_details( ) result.in_file = self._current_file logger.debug('Parser : Creating model element: %s with kind:%s', name, kind) return result
def process_swingame_attribute(self, token): tok = self._match_token('number') lib = find_or_add_class('lib') lib.version = tok[1]
def set_tag(self, title, other = None): if title == "params": #process parameter comments for param_details in other: param_name = param_details[0] param_doc = param_details[1] done = False for param in self.params: if param.name == param_name: param.add_doc(param_doc) done = True break if not done: logger.error('Method : Unable to find parameter %s for %s', param_name, self.uname) assert False elif title == 'related_params': # The parameters have related documentation # The passed in details has the param name, and the list of its related # parameters for related_param_details in other: param_name = related_param_details[0] related_params = related_param_details[1] # Find the parameter done = False for param in self.params: # if this is the parameter... if param.name == param_name: # then add related docs param.add_related_params(related_params) done = True break if not done: logger.error('Method : Unable to find parameter %s for %s', param_name, self.uname) assert False elif title == 'updatesArrayParams': # check which parameters are being updated and mark so that checking ignores them for idx in other: self.params[idx - 1].being_updated = True elif title == "class": #the class indicates that the @method is for this other class... from sg_code_module import SGCodeModule from sg_library import SGLibrary if other == None: super(SGMethod,self).set_tag(title, None) return elif isinstance(other, SGCodeModule): other_class = other elif isinstance(other, SGLibrary): other_class = other else: other_class = find_or_add_class(other) super(SGMethod,self).set_tag('other_class', other_class) elif title == 'getter' or title == 'setter': # 1: mark as getter/setter super(SGMethod,self).set_tag('is_' + title, True) # 2: set property name self.in_property = other # 3: mark for later processing mthd = SGMethod(other + ' ' + title) super(SGMethod,self).set_tag('class_method', mthd) elif title == 'constructor': const = SGMethod(self.other_class.name) const.is_constructor = True super(SGMethod,self).set_tag('class_method', const) elif title == 'dispose': dest = SGMethod("~" + self.other_class.name) dest.is_destructor = True self.mimic_destructor = True super(SGMethod,self).set_tag('class_method', dest) elif title == 'csn': #assign the 'csn' class special name to the class method if self.class_method == None: logger.error('Model Error: Method %s has a csn before the method/property/constructor definition - or should be sn.', self.name) assert False self.class_method.set_tag('sn', other) else: super(SGMethod,self).set_tag(title, other)
def set_tag(self, title, other=None): if title == "params": #process parameter comments for param_details in other: param_name = param_details[0] param_doc = param_details[1] done = False for param in self.params: if param.name == param_name: param.add_doc(param_doc) done = True break if not done: logger.error( 'Method : Unable to find parameter %s for %s', param_name, self.uname) assert False elif title == 'related_params': # The parameters have related documentation # The passed in details has the param name, and the list of its related # parameters for related_param_details in other: param_name = related_param_details[0] related_params = related_param_details[1] # Find the parameter done = False for param in self.params: # if this is the parameter... if param.name == param_name: # then add related docs param.add_related_params(related_params) done = True break if not done: logger.error( 'Method : Unable to find parameter %s for %s', param_name, self.uname) assert False elif title == 'updatesArrayParams': # check which parameters are being updated and mark so that checking ignores them for idx in other: self.params[idx - 1].being_updated = True elif title == "class": #the class indicates that the @method is for this other class... from sg_code_module import SGCodeModule from sg_library import SGLibrary if other == None: super(SGMethod, self).set_tag(title, None) return elif isinstance(other, SGCodeModule): other_class = other elif isinstance(other, SGLibrary): other_class = other else: other_class = find_or_add_class(other) super(SGMethod, self).set_tag('other_class', other_class) elif title == 'getter' or title == 'setter': # 1: mark as getter/setter super(SGMethod, self).set_tag('is_' + title, True) # 2: set property name self.in_property = other # 3: mark for later processing mthd = SGMethod(other + ' ' + title) super(SGMethod, self).set_tag('class_method', mthd) elif title == 'constructor': const = SGMethod(self.other_class.name) const.is_constructor = True super(SGMethod, self).set_tag('class_method', const) elif title == 'dispose': dest = SGMethod("~" + self.other_class.name) dest.is_destructor = True self.mimic_destructor = True super(SGMethod, self).set_tag('class_method', dest) elif title == 'csn': #assign the 'csn' class special name to the class method if self.class_method == None: logger.error( 'Model Error: Method %s has a csn before the method/property/constructor definition - or should be sn.', self.name) assert False self.class_method.set_tag('sn', other) else: super(SGMethod, self).set_tag(title, other)