Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
builtin_names))
# The meta-data for these lives in a Fortran module file
# passed in to this method.
fname = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
builtin_defs_file)
if not os.path.isfile(fname):
raise ParseError(
"BuiltInKernelTypeFactory:create Kernel '{0}' is a recognised "
"Built-in but cannot find file '{1}' containing the meta-data "
"describing the Built-in operations for API '{2}'"
.format(name, fname, self._type))
# Attempt to parse the meta-data
try:
parsefortran.FortranParser.cache.clear()
fparser.logging.disable(fparser.logging.CRITICAL)
parse_tree = fpapi.parse(fname)
except Exception:
raise ParseError(
"BuiltInKernelTypeFactory:create: Failed to parse the meta-"
"data for PSyclone built-ins in file '{0}'.".format(fname))
# Now we have the parse tree, call our parent class to create \
# the object
return KernelTypeFactory.create(self, parse_tree, name)
# pylint: enable=too-few-public-methods
# passed in to this method.
fname = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
builtin_defs_file)
if not os.path.isfile(fname):
from psyclone.parse import ParseError
raise ParseError(
"Kernel '{0}' is a recognised Built-in but cannot "
"find file '{1}' containing the meta-data describing "
"the Built-in operations for API '{2}'".format(name,
fname,
self._type))
# Attempt to parse the meta-data
try:
parsefortran.FortranParser.cache.clear()
fparser.logging.disable(fparser.logging.CRITICAL)
ast = fpapi.parse(fname)
except:
from psyclone.parse import ParseError
raise ParseError(
"Failed to parse the meta-data for PSyclone "
"built-ins in {0}".format(fname))
# Now we have the AST, call our parent class to create the object
return KernelTypeFactory.create(self, ast, name)
def get_kernel_parse_tree(filepath):
'''Parse the file in filepath with fparser1 and return a parse tree.
:param str filepath: path to a file (hopefully) containing \
PSyclone kernel code.
:returns: Parse tree of the kernel code contained in the specified \
file.
:rtype: :py:class:`fparser.one.block_statements.BeginSource`
:raises ParseError: if fparser fails to parse the file
'''
parsefortran.FortranParser.cache.clear()
fparser.logging.disable(fparser.logging.CRITICAL)
try:
parse_tree = fpapi.parse(filepath)
# parse_tree includes an extra comment line which contains
# file details. This line can be long which can cause line
# length issues. Therefore set the information (name) to be
# empty.
parse_tree.name = ""
except Exception:
raise ParseError(
"Failed to parse kernel code '{0}'. Is the Fortran "
"correct?".format(filepath))
return parse_tree
'''
if api == "":
api = DEFAULTSTUBAPI
if api not in SUPPORTEDSTUBAPIS:
print "Unsupported API '{0}' specified. Supported API's are {1}.".\
format(api, SUPPORTEDSTUBAPIS)
raise GenerationError(
"generate: Unsupported API '{0}' specified. Supported types are "
"{1}.".format(api, SUPPORTEDSTUBAPIS))
if not os.path.isfile(filename):
raise IOError("file '{0}' not found".format(filename))
# drop cache
fparser.parsefortran.FortranParser.cache.clear()
fparser.logging.disable('CRITICAL')
try:
ast = fpapi.parse(filename, ignore_comments=False)
except AttributeError:
raise ParseError("Code appears to be invalid Fortran")
metadata = DynKernMetadata(ast)
kernel = DynKern()
kernel.load_meta(metadata)
return kernel.gen_stub
'''
if api == "":
api = Config.get().default_stub_api
if api not in Config.get().supported_stub_apis:
print("Unsupported API '{0}' specified. Supported API's are {1}.".
format(api, Config.get().supported_stub_apis))
raise GenerationError(
"generate: Unsupported API '{0}' specified. Supported types are "
"{1}.".format(api, Config.get().supported_stub_apis))
if not os.path.isfile(filename):
raise IOError("file '{0}' not found".format(filename))
# drop cache
fparser.one.parsefortran.FortranParser.cache.clear()
fparser.logging.disable(fparser.logging.CRITICAL)
try:
ast = fparser.api.parse(filename, ignore_comments=False)
except (fparser.common.utils.AnalyzeError, AttributeError) as error:
raise ParseError("Code appears to be invalid Fortran: " +
str(error))
metadata = DynKernMetadata(ast)
kernel = DynKern()
kernel.load_meta(metadata)
return kernel.gen_stub
builtin_names))
# The meta-data for these lives in a Fortran module file
# passed in to this method.
fname = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
builtin_defs_file)
if not os.path.isfile(fname):
raise ParseError(
"BuiltInKernelTypeFactory:create Kernel '{0}' is a recognised "
"Built-in but cannot find file '{1}' containing the meta-data "
"describing the Built-in operations for API '{2}'"
.format(name, fname, self._type))
# Attempt to parse the meta-data
try:
parsefortran.FortranParser.cache.clear()
fparser.logging.disable(fparser.logging.CRITICAL)
parse_tree = fpapi.parse(fname)
except Exception:
raise ParseError(
"BuiltInKernelTypeFactory:create: Failed to parse the meta-"
"data for PSyclone built-ins in file '{0}'.".format(fname))
# Now we have the parse tree, call our parent class to create \
# the object
return KernelTypeFactory.create(self, parse_tree, name)
# pylint: enable=too-few-public-methods