Changeset 1ddb794 in sasmodels for sasmodels/py2c.py
- Timestamp:
- Dec 18, 2017 10:48:16 AM (6 years ago)
- Children:
- 8224d24
- Parents:
- 98a4f14
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/py2c.py
r98a4f14 r1ddb794 243 243 # for C 244 244 for arg in node.args: 245 self.arguments.append(arg.arg) 245 # CRUFT: 2.7 uses arg.id, 3.x uses arg.arg 246 try: 247 arg_name = arg.arg 248 except AttributeError: 249 arg_name = arg.id 250 self.arguments.append(arg_name) 246 251 247 252 padding = [None] *(len(node.args) - len(node.defaults)) 248 253 for arg, default in zip(node.args, padding + node.defaults): 249 254 if default is not None: 250 self.warnings.append("Default Parameter unknown to C") 251 w_str = "Default Parameters are unknown to C: '" + arg.arg + \ 252 " = " + str(default.n) + "'" 255 # CRUFT: 2.7 uses arg.id, 3.x uses arg.arg 256 # CRUFT: 2.7 uses arg.id, 3.x uses arg.arg 257 try: 258 arg_name = arg.arg 259 except AttributeError: 260 arg_name = arg.id 261 w_str = ("Default Parameters are unknown to C: '%s = %s" 262 % arg_name, str(default.n)) 253 263 self.warnings.append(w_str) 254 264 # self.write_python('=') … … 305 315 if(len(self.Tuples) > 0): 306 316 tplTargets = list(self.Tuples) 307 self.Tuples.clear()317 del self.Tuples[:] 308 318 self.write_c(' = ') 309 319 self.is_sequence = False … … 410 420 self.c_proc.insert(start_var, c_dcl + "\n") 411 421 start_var += 1 412 self.C_Vars.clear()413 self.C_IntVars.clear()414 self.C_Vectors.clear()415 self.C_Pointers.clear()422 del self.C_Vars[:] 423 del self.C_IntVars[:] 424 del self.C_Vectors[:] 425 del self.C_Pointers[:] 416 426 self.C_DclPointers 417 427 if(fLine == True): … … 427 437 self.c_proc.insert(start_var + 1, "\n") 428 438 429 def writeInclude(self):430 if(self.MathIncludeed == False):431 self.add_c_line("#include <math.h>\n")432 self.add_c_line("static double pi = 3.14159265359;\n")433 self.MathIncludeed = True434 435 439 def ListToString(self, strings): 436 440 s = '' … … 475 479 476 480 self.visit(node.args) 477 # for C478 # self.writeInclude()479 481 self.getMethodSignature() 480 482 # for C … … 802 804 if((name not in self.C_Functions) and (name not in self.C_Vars) and \ 803 805 (name not in self.C_IntVars) and (name not in self.arguments) and \ 804 (name.is numeric() == False)):806 (name.isdigit() == False)): 805 807 if(self.InSubscript): 806 808 self.C_IntVars.append(node.id) … … 1101 1103 1102 1104 def translate(functions, constants=0): 1103 sniplets = [] 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) 1105 snippets = [] 1106 for source, fname, line_no in functions: 1107 line_directive = '#line %d "%s"'%(line_no, fname.replace('\\','\\\\')) 1108 snippets.append(line_directive) 1110 1109 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() 1117 return("\n".join(sniplets)) 1110 # in the future add filename, offset, constants 1111 c_code = to_source(tree, functions) 1112 snippets.append(c_code) 1113 return snippets 1118 1114 1119 1115 def get_file_names():
Note: See TracChangeset
for help on using the changeset viewer.