Peano
Loading...
Searching...
No Matches
Boolean.py
Go to the documentation of this file.
1# This file is part of the DaStGen2 project. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
3from .Attribute import Attribute
4
5
8 self,
9 name,
10 ifdefs=[],
11 qualifier=Attribute.Qualifier.NONE,
12 initval=None,
13 ):
14 # Do we need to expose this attribute in the header file?
15 # Only necessary for functions that will be inlined, i.e. constexpr
16 expose = qualifier == Attribute.Qualifier.CONSTEXPR
17
18 Attribute.__init__(
19 self,
20 name,
21 ifdefs,
22 qualifier=qualifier,
23 initval=initval,
24 expose_in_header_file=expose,
25 )
26
27 self.compress = True
28
29 return
30
31 def get_methods(self, _full_qualified_class_name, for_declaration=True):
32 accessor_name = self.get_accessor_name()
33 methods = []
34
35 if self._is_static:
36 if for_declaration:
37 # No 'const' here: static member function cannot have 'const' qualifier
38 getter = ("get" + accessor_name + "()", "static bool")
39 else:
40 # No 'static' here: 'static' can only be specified inside the class definition
41 getter = ("get" + accessor_name + "()", "bool")
42
43 elif self._is_const_static:
44 if for_declaration:
45 # No 'const' here: static member function cannot have 'const' qualifier
46 getter = ("get" + accessor_name + "()", "static bool")
47 else:
48 # No 'static' here: 'static' can only be specified inside the class definition
49 # No 'const' here either: function definition will then differ from that in declaration
50 getter = ("get" + accessor_name + "()", "bool")
51
52 elif self._is_const:
53 getter = ("get" + accessor_name + "() const", "const bool")
54
56 getter = ("get" + accessor_name + "() const", "constexpr bool")
57
58 else:
59 # default case.
60 getter = ("get" + accessor_name + "() const", "bool")
61
62 methods.append(getter)
63
64 # Add a setter method, if it makes sense.
66 methods.append(("set" + accessor_name + "(bool value)", "void"))
67
68 return methods
69
70 def get_plain_C_attributes(self, for_constructor=False):
71 typestring = "bool"
72 namestring = "_" + self._name
73
74 # add const/static qualifiers and initialization values, if needed
75 if self._is_static:
76 typestring = "inline static bool"
77 if self._initval is not None:
78 namestring += " = " + str(self._initval)
79
80 elif self._is_const_static:
81 typestring = "inline const static bool"
82 namestring += " = " + str(self._initval)
83
84 elif self._is_const:
85 typestring = "const bool"
86 namestring += " = " + str(self._initval)
87
89 typestring = "constexpr static bool"
90 namestring += " = " + str(self._initval)
91
92 else:
93 # default case
94 # If an initial value is provided, add it
95 # However, only add it if we need it for a definition,
96 # not as optional argument for constructor method
97 if self._initval is not None and not for_constructor:
98 namestring += " = " + str(self._initval)
99
100 if (
101 self.compress
102 and not self._is_static
103 and not self._is_const_static
104 and not self._is_const
105 and not self._is_constexpr_is_constexpr
106 ):
107 packstring = "[[clang::pack]]"
108 return [(namestring, typestring, packstring)]
109 else:
110 return [(namestring, typestring, "")]
111
112 def get_method_body(self, signature):
113 if signature.startswith("get") and self.use_data_store:
114 return " return _dataStore._" + self._name + ";\n"
115 elif signature.startswith("get") and not self.use_data_store:
116 return " return _" + self._name + ";\n"
117 elif signature.startswith("set") and self.use_data_store:
118 return " _dataStore._" + self._name + " = value;\n"
119 elif signature.startswith("set") and not self.use_data_store:
120 return " _" + self._name + " = value;\n"
121 else:
122 assert False
123 return ""
124
126 """
127
128 I originally wanted to map the booleans to MPI_CXX_BOOL. But
129 neither CXX_BOOL nor C_BOOL work for the Intel archtiectures.
130 All the datatypes that I use then seg fault. If I however map
131 the bool to an integer, then it seems to work.
132
133 """
134 # return [ ("MPI_C_BOOL", 1) ]
135 return [("MPI_BYTE", 1)]
136
137 def get_to_string(self):
138 """
139
140 Return string representation of attribute.
141
142 """
143 if self.use_data_store:
144 return "_dataStore._" + self._name
145 else:
146 return "_" + self._name
Represents one attribute.
Definition Attribute.py:8
get_accessor_name(self)
Generate the accessor name used throughout dastgen2 to create variables, function names,...
Definition Attribute.py:259
get_methods(self, _full_qualified_class_name, for_declaration=True)
Return sequence of methods that are defined for this attribute.
Definition Boolean.py:31
__init__(self, name, ifdefs=[], qualifier=Attribute.Qualifier.NONE, initval=None)
name: String This is a plain string which has to follow the C++ naming conventions,...
Definition Boolean.py:13
get_to_string(self)
Return string representation of attribute.
Definition Boolean.py:137
get_method_body(self, signature)
I hand in the method signature (see get_methods()) and wanna get the whole implementation.
Definition Boolean.py:112
get_native_MPI_type(self)
I originally wanted to map the booleans to MPI_CXX_BOOL.
Definition Boolean.py:125
get_plain_C_attributes(self, for_constructor=False)
Return list of n-tuples.
Definition Boolean.py:70