def __str__(self): """Return a string of the declaration of the type""" if self.default_kind: return self.typestr elif check_fortran_intrinsic(self.typestr): return "{}(kind={})".format(self.typestr, self._kind) else: # Derived type return "{}({})".format(self.typestr, self._kind)
def __init__(self, typestr_in=None, kind_in=None, line_in=None, context=None): if context is None: self._context = ParseContext() else: self._context = ParseContext(context=context) # We have to distinguish which type of initialization we have if typestr_in is not None: if line_in is not None: raise ParseInternalError( "typestr_in and line_in cannot both be used in a single call", self._context) # End if self._typestr = typestr_in self.default_kind = kind_in is None if kind_in is None: self._kind = None elif kind_in[0] == '(': # Parse an explicit kind declaration self._kind = self.parse_kind_selector(kind_in) else: # The kind has already been parsed for us (e.g., by character) self._kind = kind_in elif kind_in is not None: raise ParseInternalError( "kind_in cannot be passed without typestr_in", self._context) elif line_in is not None: match = Ftype.type_match(line_in) self._match_len = len(match.group(0)) if match is None: raise ParseSyntaxError("type declaration", token=line_in, context=self._context) elif check_fortran_intrinsic(match.group(1)): self._typestr = match.group(1) if match.group(2) is not None: # Parse kind section self._kind = self.parse_kind_selector( match.group(2).strip()) else: self._kind = None # End if self.default_kind = self._kind is None else: raise ParseSyntaxError("type declaration", token=line_in, context=self._context) else: raise ParseInternalError( "At least one of typestr_in or line must be passed", self._context)
def __init__(self, typestr_in=None, kind_in=None, match_len_in=None, line_in=None, context=None): """Initialize this FType object, either using <typestr_in> and <kind_in>, OR using line_in.""" if context is None: self.__context = ParseContext() else: self.__context = ParseContext(context=context) # end if # We have to distinguish which type of initialization we have self.__typestr = typestr_in if typestr_in is not None: if line_in is not None: emsg = "Cannot pass both typestr_in and line_in as arguments" raise ParseInternalError(emsg, self.__context) # end if self.__default_kind = kind_in is None if kind_in is None: self.__kind = None elif kind_in[0] == '(': # Parse an explicit kind declaration self.__kind = self.parse_kind_selector(kind_in) else: # The kind has already been parsed for us (e.g., by character) self.__kind = kind_in # end if if match_len_in is not None: self.__match_len = match_len_in else: self.__match_len = len(self.typestr) if kind_in is not None: self.__match_len += len(self.__kind) + 2 # end if # end if elif kind_in is not None: emsg = "kind_in cannot be passed without typestr_in" raise ParseInternalError(emsg, self.__context) elif line_in is not None: match = Ftype.type_match(line_in) if match is None: emsg = "type declaration" raise ParseSyntaxError(emsg, token=line_in, context=self.__context) # end if if match_len_in is not None: self.__match_len = match_len_in else: self.__match_len = len(match.group(0)) # end if if check_fortran_intrinsic(match.group(1)): self.__typestr = match.group(1) if match.group(2) is not None: # Parse kind section kmatch = match.group(2).strip() self.__kind = self.parse_kind_selector(kmatch) else: self.__kind = None # end if self.__default_kind = self.__kind is None else: raise ParseSyntaxError("type declaration", token=line_in, context=self.__context) # end if else: emsg = "At least one of typestr_in or line_in must be passed" raise ParseInternalError(emsg, self.__context)