pyccel.naming.fortrannameclashchecker module#

Handles name clash problems in Fortran.

class pyccel.naming.fortrannameclashchecker.FortranNameClashChecker(self)[source]#

Bases: LanguageNameClashChecker

Class containing functions to help avoid problematic names in Fortran.

A class which provides functionalities to check or propose variable names and verify that they do not cause name clashes. Name clashes may be due to capitalisation (as Fortran is not case-sensitive), or due to the use of reserved keywords.

get_collisionless_name(name, symbols)[source]#

Get a valid name which doesn’t collide with symbols or Fortran keywords.

Find a new name based on the suggested name which will not cause conflicts with Fortran keywords, does not conflict with the provided symbols, and is a valid name in Fortran code.

Parameters:
  • name (str) – The suggested name.

  • symbols (set) – Symbols which should be considered as collisions.

Returns:

A new name which is collision free.

Return type:

str

has_clash(name, symbols)[source]#

Indicate whether the proposed name causes any clashes.

Indicate whether the proposed name causes any clashes by comparing it with the reserved keywords and the symbols which are already defined in the scope. The comparison is carried out without case sensitviity to match Fortran’s behaviour.

Parameters:
  • name (str) – The proposed name.

  • symbols (set of str) – The symbols already used in the scope.

Returns:

True if the name clashes with an existing name. False otherwise.

Return type:

bool

keywords = {'abs', 'abstract', 'acos', 'allocatable', 'allocate', 'asin', 'assign', 'associate', 'asynchronous', 'atan', 'backspace', 'bind', 'block', 'blockdata', 'c_associated', 'c_f_pointer', 'c_loc', 'c_malloc', 'c_ptr', 'c_size_t', 'call', 'case', 'class', 'close', 'codimension', 'common', 'concurrent', 'contains', 'contiguous', 'continue', 'cos', 'count', 'critical', 'cycle', 'data', 'deallocate', 'deferred', 'dimension', 'do', 'elemental', 'else', 'elseif', 'elsewhere', 'end', 'endfile', 'endfunction', 'endif', 'endmodule', 'endprogram', 'endsubroutine', 'entry', 'enum', 'enumerator', 'equivalence', 'error', 'exit', 'exp', 'extends', 'external', 'final', 'floor', 'flush', 'forall', 'format', 'fraction', 'function', 'generic', 'goto', 'if', 'implicit', 'import', 'include', 'int', 'intent', 'interface', 'intrinsic', 'lock', 'log', 'max', 'mod', 'module', 'namelist', 'nint', 'non_overridable', 'nopass', 'nullify', 'numpy_sign', 'only', 'open', 'operator', 'optional', 'pack', 'parameter', 'pass', 'pause', 'pointer', 'print', 'private', 'procedure', 'program', 'protected', 'public', 'pure', 'read', 'real', 'recursive', 'result', 'return', 'rewind', 'rewrite', 'save', 'select', 'sequence', 'sin', 'sqrt', 'stop', 'storage_size', 'submodule', 'subroutine', 'sync', 'tan', 'target', 'test', 'then', 'unlock', 'use', 'value', 'volatile', 'wait', 'where', 'while', 'write'}#