7
7
"""This file contains different utilities for the Parser."""
8
8
import os
9
9
10
- from sympy import srepr
11
-
12
10
from pyccel .ast .variable import DottedName
13
- from pyccel .parser .extend_tree import CommentLine
14
11
from pyccel .ast .internals import PyccelSymbol
15
12
16
- __all__ = ('pyccel_external_lib' , 'read_file' , 'is_valid_filename_py' ,
17
- 'is_valid_filename_pyh' , 'header_statement' , 'accelerator_statement' ,
18
- 'get_module_name' , 'view_tree' , 'get_default_path' )
13
+ __all__ = ('is_valid_filename_py' ,
14
+ 'is_valid_filename_pyh' ,
15
+ 'get_default_path' ,
16
+ 'pyccel_external_lib' )
19
17
20
18
pyccel_external_lib = {"mpi4py" : "pyccel.stdlib.external.mpi4py" ,
21
19
"scipy.linalg.lapack" : "pyccel.stdlib.external.lapack" ,
26
24
27
25
#==============================================================================
28
26
29
- def read_file (filename ):
30
- """Returns the source code from a filename."""
31
- f = open (filename )
32
- code = f .read ()
33
- f .close ()
34
- return code
35
-
36
27
# ... checking the validity of the filenames, using absolute paths
37
28
def _is_valid_filename (filename , ext ):
38
29
"""Returns True if filename has the extension ext and exists."""
@@ -55,76 +46,30 @@ def is_valid_filename_pyh(filename):
55
46
return _is_valid_filename (filename , 'pyh' )
56
47
# ...
57
48
58
- # ...
59
- def header_statement (stmt , accel ):
60
- """Returns stmt if a header statement. otherwise it returns None.
61
- this function can be used as the following
62
- >>> if header_statement(stmt):
63
- # do stuff
64
- ...
65
-
49
+ def get_default_path (name ):
66
50
"""
67
- if not isinstance (stmt , CommentLine ): return None
68
- if not stmt .value .startswith ('#$' ): return None
69
-
70
- header = stmt .value [2 :].lstrip ()
71
- if not header .startswith ('header' ): return None
72
-
73
- return stmt .value
74
- # ...
75
-
76
- # ... utilities for parsing OpenMP/OpenACC directives
77
- def accelerator_statement (stmt , accel ):
78
- """Returns stmt if an accelerator statement. otherwise it returns None.
79
- this function can be used as the following
80
- >>> if accelerator_statement(stmt, 'omp'):
81
- # do stuff
82
- ...
83
-
84
- In general you can use the functions omp_statement and acc_statement
51
+ Get the full path to the Pyccel description of the imported library.
52
+
53
+ This function takes the name of an import source. If the imported library is in
54
+ stdlib, it returns the full Python path to the stdlib equivalent library.
55
+ Otherwise the original name is returned. This equivalent library should be a
56
+ header file which describes all the functions which are supported by Pyccel.
57
+
58
+ Parameters
59
+ ----------
60
+ name : PyccelSymbol | DottedName
61
+ The name of the source file for the import.
62
+
63
+ Returns
64
+ -------
65
+ PyccelSymbol | DottedName
66
+ The name of the Pyccel-compatible source file for the import.
85
67
"""
86
- assert (accel in ['omp' , 'acc' ])
87
-
88
- if not isinstance (stmt , CommentLine ): return None
89
- if not stmt .value .startswith ('#$' ): return None
90
-
91
- directive = stmt .value [2 :].lstrip ()
92
- if not directive .startswith (accel ): return None
93
-
94
- return stmt .value
95
-
96
- omp_statement = lambda x : accelerator_statement (x , 'omp' )
97
- acc_statement = lambda x : accelerator_statement (x , 'acc' )
98
- # ...
99
-
100
- def get_module_name ( dotted_as_node ):
101
- code_name = dotted_as_node .target
102
- if (code_name != "" ):
103
- return [ code_name ]
68
+ name_ = str (name )
69
+ name = pyccel_external_lib .get (name_ , name_ ).split ('.' )
70
+ if len (name )> 1 :
71
+ return DottedName (* name )
104
72
else :
105
- import_name = dotted_as_node .value
106
- return import_name .dumps ().split ('.' )
107
-
108
-
109
- # ... utilities
110
- def view_tree (expr ):
111
- """Views a sympy expression tree."""
112
- print (srepr (expr ))
113
- # ...
114
-
115
- def get_default_path (name ):
116
- """this function takes a an import name
117
- and returns the path full bash of the library
118
- if the library is in stdlib"""
119
- name_ = name
120
- if isinstance (name , (DottedName , PyccelSymbol )):
121
- name_ = str (name )
122
- if name_ in pyccel_external_lib .keys ():
123
- name = pyccel_external_lib [name_ ].split ('.' )
124
- if len (name )> 1 :
125
- return DottedName (* name )
126
- else :
127
- return name [0 ]
128
- return name
73
+ return name [0 ]
129
74
130
75
0 commit comments