pyccel.naming.cnameclashchecker module#

Handles name clash problems in C

class pyccel.naming.cnameclashchecker.CNameClashChecker(self)[source]#

Bases: LanguageNameClashChecker

Class containing functions to help avoid problematic names in C.

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 new variables, or due to the use of reserved keywords.

get_collisionless_name(name, symbols)[source]#

Get a valid name which doesn’t collision with symbols or C keywords.

Find a new name based on the suggested name which will not cause conflicts with C keywords, does not appear in the provided symbols, and is a valid name in C 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.

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 = {'Decimal128', 'I', 'STC_CSPAN_INDEX_TYPE', '_Alignas', '_Alignof', '_Atomic', '_Bool', '_Complex', '_Decimal32', '_Decimal64', '_Generic', '_Imaginary', '_Noreturn', '_Static_assert', '_Thread_local', 'array_bool_1d', 'array_bool_2d', 'array_bool_3d', 'array_double_1d', 'array_double_2d', 'array_double_3d', 'array_double_complex_1d', 'array_double_complex_2d', 'array_double_complex_3d', 'array_float_1d', 'array_float_2d', 'array_float_3d', 'array_float_complex_1d', 'array_float_complex_2d', 'array_float_complex_3d', 'array_int32_1d', 'array_int32_2d', 'array_int32_3d', 'array_int64_1d', 'array_int64_2d', 'array_int64_3d', 'auto', 'break', 'c_ALL', 'c_COLMAJOR', 'c_END', 'c_ROWMAJOR', 'c_foreach', 'case', 'char', 'complex_max', 'complex_min', 'const', 'continue', 'csign', 'cspan_copy', 'cspan_md_layout', 'cspan_slice', 'cspan_transpose', 'default', 'do', 'double', 'else', 'enum', 'extern', 'float', 'for', 'fsign', 'goto', 'if', 'inline', 'int', 'isign', 'long', 'register', 'restrict', 'return', 'short', 'signed', 'sizeof', 'static', 'struct', 'switch', 'typedef', 'union', 'unsigned', 'using_cspan', 'void', 'volatile', 'whie'}#