Changeset 98a4f14 in sasmodels
- Timestamp:
- Dec 15, 2017 2:34:17 PM (7 years ago)
- Children:
- d9341fa, 1ddb794
- Parents:
- fa74acf
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/py2c.py
rfa74acf r98a4f14 292 292 def add_semi_colon(self): 293 293 semi_pos = self.current_statement.find(';') 294 if(semi_pos < 0): 295 self.write_c(';') 294 if(semi_pos > 0.0): 295 self.current_statement = self.current_statement.replace(';','') 296 self.write_c(';') 296 297 297 298 def visit_Assign(self, node): … … 475 476 self.visit(node.args) 476 477 # for C 477 self.writeInclude()478 # self.writeInclude() 478 479 self.getMethodSignature() 479 480 # for C … … 704 705 self.write_c('return(') 705 706 self.visit(node.value) 706 self.write_c(') ;')707 # self.add_current_statement(self)707 self.write_c(')') 708 self.add_semi_colon() 708 709 self.add_c_line(self.current_statement) 709 710 self.current_statement = '' … … 1101 1102 def translate(functions, constants=0): 1102 1103 sniplets = [] 1103 fname = functions[1] 1104 python_file = open(fname, "r") 1105 source = python_file.read() 1106 python_file.close() 1107 tree = ast.parse(source) 1108 sniplet = to_source(tree, functions) # in the future add filename, offset, constants 1109 sniplets.append(sniplet) 1104 sniplets.append("#include <math.h>") 1105 sniplets.append("static double pi = 3.14159265359;") 1106 for source,fname,line_no in functions: 1107 line_directive = '#line %d "%s"' %(line_no,fname) 1108 line_directive = line_directive.replace('\\','\\\\') 1109 # sniplets.append(line_directive) 1110 tree = ast.parse(source) 1111 sniplet = to_source(tree, functions) # in the future add filename, offset, constants 1112 sniplets.append(sniplet) 1113 c_code = "\n".join(sniplets) 1114 f_out = open ("xlate.c", "w+") 1115 f_out.write (c_code) 1116 f_out.close() 1110 1117 return("\n".join(sniplets)) 1111 1118
Note: See TracChangeset
for help on using the changeset viewer.