Peano
Loading...
Searching...
No Matches
Integer.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 min_value=None,
11 max_value=None,
12 ifdefs=[],
13 qualifier=Attribute.Qualifier.NONE,
14 initval=None,
15 ):
16 """
17
18 min_value: None or integer value
19 Has to be smaller than max_value. Can also be a string if this string
20 is given by the precompiler.
21
22 """
23
24 # Do we need to expose this attribute in the header file?
25 # Only necessary for functions that will be inlined, i.e. constexpr
26 expose = qualifier == Attribute.Qualifier.CONSTEXPR
27
28 Attribute.__init__(
29 self,
30 name,
31 ifdefs,
32 qualifier=qualifier,
33 initval=initval,
34 expose_in_header_file=expose,
35 )
36 self._min_value = min_value
37 self._max_value = max_value
38
39 return
40
41 def get_methods(self, _full_qualified_class_name, for_declaration=True):
42 accessor_name = self.get_accessor_name()
43 methods = []
44
45 if self._is_static:
46 if for_declaration:
47 # No 'const' here: static member function cannot have 'const' qualifier
48 getter = ("get" + accessor_name + "()", "static int")
49 else:
50 # No 'static' here: 'static' can only be specified inside the class definition
51 getter = ("get" + accessor_name + "()", "int")
52
53 elif self._is_const_static:
54 if for_declaration:
55 # No 'const' here: static member function cannot have 'const' qualifier
56 getter = ("get" + accessor_name + "()", "static int")
57 else:
58 # No 'static' here: 'static' can only be specified inside the class definition
59 # No 'const' here either: function definition will then differ from that in declaration
60 getter = ("get" + accessor_name + "()", "int")
61
62 elif self._is_const:
63 getter = ("get" + accessor_name + "() const", "const int")
64
66 getter = ("get" + accessor_name + "() const", "constexpr int")
67
68 else:
69 # default case.
70 getter = ("get" + accessor_name + "() const", "int")
71
72 methods.append(getter)
73
74 # Add a setter method, if it makes sense.
76 methods.append(("set" + accessor_name + "(int value)", "void"))
77
78 return methods
79
80 def get_plain_C_attributes(self, for_constructor=False):
81 typestring = "int"
82 namestring = "_" + self._name
83
84 # add const/static qualifiers and initialization values, if needed
85 if self._is_static:
86 typestring = "inline static int"
87 if self._initval is not None:
88 namestring += " = " + str(self._initval)
89
90 elif self._is_const_static:
91 typestring = "inline const static int"
92 namestring += " = " + str(self._initval)
93
94 elif self._is_const:
95 typestring = "const int"
96 namestring += " = " + str(self._initval)
97
99 typestring = "constexpr static int"
100 namestring += " = " + str(self._initval)
101
102 else:
103 # default case
104 # If an initial value is provided, add it
105 # However, only add it if we need it for a definition,
106 # not as optional argument for constructor method
107 if self._initval is not None and not for_constructor:
108 namestring += " = " + str(self._initval)
109
110 # Set up compression/packaging
111 if self._min_value is None and self._max_value is None:
112 return [(namestring, typestring, "")]
113 else:
114 packstring = (
115 "[[clang::pack_range("
116 + str(self._min_value)
117 + ","
118 + str(self._max_value)
119 + ")]]"
120 )
121 return [(namestring, typestring, packstring)]
122
123 def get_method_body(self, signature):
124 if signature.startswith("get") and self.use_data_store:
125 return " return _dataStore._" + self._name + ";\n"
126 elif signature.startswith("get") and not self.use_data_store:
127 return " return _" + self._name + ";\n"
128 elif signature.startswith("set") and self.use_data_store:
129 return " _dataStore._" + self._name + " = value;\n"
130 elif signature.startswith("set") and not self.use_data_store:
131 return " _" + self._name + " = value;\n"
132 else:
133 assert False
134 return ""
135
137 return [("MPI_INT", 1)]
138
139 def get_to_string(self):
140 """
141
142 Return string representation of attribute.
143
144 """
145 if self.use_data_store:
146 return "_dataStore._" + self._name
147 else:
148 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_native_MPI_type(self)
Return native (built-in) MPI datatype.
Definition Integer.py:136
__init__(self, name, min_value=None, max_value=None, ifdefs=[], qualifier=Attribute.Qualifier.NONE, initval=None)
min_value: None or integer value Has to be smaller than max_value.
Definition Integer.py:15
get_method_body(self, signature)
I hand in the method signature (see get_methods()) and wanna get the whole implementation.
Definition Integer.py:123
get_to_string(self)
Return string representation of attribute.
Definition Integer.py:139
get_methods(self, _full_qualified_class_name, for_declaration=True)
Return sequence of methods that are defined for this attribute.
Definition Integer.py:41
get_plain_C_attributes(self, for_constructor=False)
Return list of n-tuples.
Definition Integer.py:80