(self, expr, assign_to=None)
return result
Actually format the expression as C code.
Actually format the expression as C code.
Actually format the expression as C code .
def doprint(self, expr, assign_to=None):
        """
        Actually format the expression as C code.
        """

        if isinstance(assign_to, string_types):
            assign_to = C.Symbol(assign_to)
        elif not isinstance(assign_to, (C.Basic, type(None))):
            raise TypeError("CCodePrinter cannot assign to object of type %s" %
                    type(assign_to))

        # keep a set of expressions that are not strictly translatable to C
        # and number constants that must be declared and initialized
        not_c = self._not_supported = set()
        self._number_symbols = set()

        # We treat top level Piecewise here to get if tests outside loops
        lines = []
        if isinstance(expr, C.Piecewise):
            for i, (e, c) in enumerate(expr.args):
                if i == 0:
                    lines.append("if (%s) {" % self._print(c))
                elif i == len(expr.args) - 1 and c == True:
                    lines.append("else {")
                else:
                    lines.append("else if (%s) {" % self._print(c))
                code0 = self._doprint_a_piece(e, assign_to)
                lines.extend(code0)
                lines.append("}")
        else:
            code0 = self._doprint_a_piece(expr, assign_to)
            lines.extend(code0)

        # format the output
        if self._settings["human"]:
            frontlines = []
            if len(not_c) > 0:
                frontlines.append("// Not C:")
                for expr in sorted(not_c, key=str):
                    frontlines.append("// %s" % repr(expr))
            for name, value in sorted(self._number_symbols, key=str):
                frontlines.append("double const %s = %s;" % (name, value))
            lines = frontlines + lines
            lines = "\n".join(lines)
            result = self.indent_code(lines)
        else:
            lines = self.indent_code("\n".join(lines))
            result = self._number_symbols, not_c, lines
        del self._not_supported
        del self._number_symbols
        return result
def doprint ( self , expr , assign_to = None ) : if isinstance ( assign_to , string_types ) : assign_to = C . Symbol ( assign_to ) elif not isinstance ( assign_to , ( C . Basic , type ( None ) ) ) : raise TypeError ( "CCodePrinter cannot assign to object of type %s" % type ( assign_to ) ) # keep a set of expressions that are not strictly translatable to C # and number constants that must be declared and initialized not_c = self . _not_supported = set ( ) self . _number_symbols = set ( ) # We treat top level Piecewise here to get if tests outside loops lines = [ ] if isinstance ( expr , C . Piecewise ) : for i , ( e , c ) in enumerate ( expr . args ) : if i == 0 : lines . append ( "if (%s) {" % self . _print ( c ) ) elif i == len ( expr . args ) - 1 and c == True : lines . append ( "else {" ) else : lines . append ( "else if (%s) {" % self . _print ( c ) ) code0 = self . _doprint_a_piece ( e , assign_to ) lines . extend ( code0 ) lines . append ( "}" ) else : code0 = self . _doprint_a_piece ( expr , assign_to ) lines . extend ( code0 ) # format the output if self . _settings [ "human" ] : frontlines = [ ] if len ( not_c ) > 0 : frontlines . append ( "// Not C:" ) for expr in sorted ( not_c , key = str ) : frontlines . append ( "// %s" % repr ( expr ) ) for name , value in sorted ( self . _number_symbols , key = str ) : frontlines . append ( "double const %s = %s;" % ( name , value ) ) lines = frontlines + lines lines = "\n" . join ( lines ) result = self . indent_code ( lines ) else : lines = self . indent_code ( "\n" . join ( lines ) ) result = self . _number_symbols , not_c , lines del self . _not_supported del self . _number_symbols return result