def process_item(self): line = self.item.get_line()[4:].lstrip() if line.startswith('('): self.isvalid = False return specs = [] i = line.find('::') if i != -1: for s in line[:i].split(','): s = s.strip() if s: specs.append(s) line = line[i + 2:].lstrip() self.specs = specs i = line.find('(') if i != -1: self.name = line[:i].rstrip() assert line[-1] == ')', repr(line) self.params = split_comma(line[i + 1:-1].lstrip()) else: self.name = line self.params = [] if not is_name(self.name): self.isvalid = False return return BeginStatement.process_item(self)
def analyze(self): content = self.content[:] if self.prefix: self.update_attributes(self.prefix.upper().split()) variables = self.a.variables for a in self.args: assert a not in variables if is_name(a): variables[a] = Variable(self, a) elif a == '*': variables[a] = Variable(self, a) # XXX: fix me appropriately else: message = 'argument must be a name or * but got %r' raise AnalyzeError(message % (a)) if isinstance(self, Function): var = variables[self.result] = Variable(self, self.result) if self.typedecl is not None: var.set_type(self.typedecl) while content: stmt = content.pop(0) if isinstance(stmt, Contains): for stmt in filter_stmts(content, SubProgramStatement): stmt.analyze() self.a.internal_subprogram[stmt.name] = stmt stmt = content.pop(0) while isinstance(stmt, Comment): stmt = content.pop(0) assert isinstance(stmt, self.end_stmt_cls), repr(stmt) elif isinstance(stmt, self.end_stmt_cls): continue else: if hasattr(stmt, "analyze"): stmt.analyze() else: message = 'Failed to parse: {0}' raise AnalyzeError(message.format(str(stmt))) if content: logger.info('Not analyzed content: %s' % content) # self.show_message('Not analyzed content: %s' % content) parent_provides = self.parent.get_provides() if parent_provides is not None: if self.name in parent_provides: message = 'module subprogram name conflict with %s, ' \ + 'overriding.' self.warning(message % (self.name)) if self.is_public(): parent_provides[self.name] = self if self.is_recursive() and self.is_elemental(): message = 'C1241 violation: prefix cannot specify both ' \ + 'ELEMENTAL and RECURSIVE' self.warning(message) return
def process_item(self): item = self.item apply_map = item.apply_map clsname = self.__class__.__name__.lower() line = item.get_line() from .block_statements import Function if not line.lower().startswith(clsname): i = 0 j = 0 for c in line: i += 1 if c==' ': continue j += 1 if j==len(clsname): break line = line[:i].replace(' ','') + line[i:] assert line.lower().startswith(clsname),repr((line,clsname)) line = line[len(clsname):].lstrip() if line.startswith('('): i = line.find(')') selector = apply_map(line[:i+1].strip()) line = line[i+1:].lstrip() elif line.startswith('*'): selector = '*' line = line[1:].lstrip() if line.startswith('('): i = line.find(')') selector += apply_map(line[:i+1].rstrip()) line = line[i+1:].lstrip() else: m = re.match(r'\d+(_\w+|)|[*]',line) if not m: self.isvalid = False return i = m.end() selector += line[:i].rstrip() line = line[i:].lstrip() else: selector = '' fm = Function.match(line) if fm: l2 = line[:fm.end()] m2 = re.match(r'.*?\b(?P<name>\w+)\Z',l2) if not m2: self.isvalid = False return fname = m2.group('name') fitem = item.copy(clsname+selector+' :: '+fname, apply_map=True) self.parent.put_item(fitem) item.clone(line) self.isvalid = False return if line.startswith(','): line = line[1:].lstrip() self.raw_selector = selector if isinstance(self, Character): self.selector = self._parse_char_selector(selector) else: self.selector = self._parse_kind_selector(selector) i = line.find('::') if i==-1: self.attrspec = [] self.entity_decls = split_comma(line, self.item) else: self.attrspec = split_comma(line[:i].rstrip(), self.item) self.entity_decls = split_comma(line[i+2:].lstrip(), self.item) for entity in self.entity_decls: if not is_entity_decl(entity): self.isvalid = False return if isinstance(self.parent, Function) \ and self.parent.name in self.entity_decls: assert self.parent.typedecl is None,repr(self.parent.typedecl) self.parent.typedecl = self self.ignore = False if (len(self.entity_decls)>1): self.entity_decls.remove(self.parent.name) else: self.ignore = True if isinstance(self, Type): self.name = self.selector[1].lower() assert is_name(self.name),repr(self.name) else: self.name = clsname return