def cs_format(self, precision=None): statement = "else" body_fmt = Indented(self.body.cs_format(precision)) if _is_simple_if_body(self.body): return (statement, body_fmt) else: return (statement, "{", body_fmt, "}")
def cs_format(self, precision=None): cases = [] for case in self.cases: caseheader = "case " + case[0].ce_format(precision) + ":" casebody = case[1].cs_format(precision) if self.autoscope: casebody = ("{", Indented(casebody), "}") if self.autobreak: casebody = (casebody, "break;") cases.extend([caseheader, Indented(casebody)]) if self.default is not None: caseheader = "default:" casebody = self.default.cs_format(precision) if self.autoscope: casebody = ("{", Indented(casebody), "}") cases.extend([caseheader, Indented(casebody)]) return ("switch (" + self.arg.ce_format(precision) + ")", "{", cases, "}")
def cs_format(self, precision=None): # Pad innermost array dimension sizes = pad_innermost_dim(self.sizes, self.padlen) # Add brackets brackets = ''.join("[%d]" % n for n in sizes) # Join declaration decl = self.typename + " " + self.symbol.name + brackets # NB! C++11 style alignas prefix syntax. # If trying other target languages, must use other syntax. if self.alignas: align = "alignas(%d)" % int(self.alignas) decl = align + " " + decl if self.values is None: # Undefined initial values return decl + ";" elif _is_zero_valued(self.values): # Zero initial values # (NB! C style zero initialization, not sure about other target languages) nb = len(sizes) return decl + " = {lbr} 0 {rbr};".format(lbr="{" * nb, rbr="}" * nb) else: # Construct initializer lists for arbitrary multidimensional array values if self.values.dtype.kind == "f": formatter = format_float elif self.values.dtype.kind == "i": formatter = format_int else: formatter = format_value initializer_lists = build_initializer_lists(self.values, self.sizes, 0, formatter, padlen=self.padlen, precision=precision) if len(initializer_lists) == 1: return decl + " = " + initializer_lists[0] + ";" else: initializer_lists[-1] += ";" # Close statement on final line return (decl + " =", Indented(initializer_lists))
def cs_format(self, precision=None): indextype = self.index_type index = self.index.ce_format(precision) begin = self.begin.ce_format(precision) end = self.end.ce_format(precision) init = indextype + " " + index + " = " + begin check = index + " < " + end update = "++" + index prelude = "for (" + init + "; " + check + "; " + update + ")" body = Indented(self.body.cs_format(precision)) # Reduce size of code with lots of simple loops by dropping {} in obviously safe cases if is_simple_inner_loop(self.body): code = (prelude, body) else: code = (prelude, "{", body, "}") # Add vectorization hint if requested if self.pragma is not None: code = (self.pragma.cs_format(), ) + code return code
def cs_format(self, precision=None): return ("{", Indented(self.body.cs_format(precision)), "}")