Type.py (10301:44839e8febbd) | Type.py (10307:6df951dcd7d9) |
---|---|
1# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 2# Copyright (c) 2009 The Hewlett-Packard Development Company 3# All rights reserved. 4# 5# Redistribution and use in source and binary forms, with or without 6# modification, are permitted provided that the following conditions are 7# met: redistributions of source code must retain the above copyright 8# notice, this list of conditions and the following disclaimer; --- 29 unchanged lines hidden (view full) --- 38 self.type = type 39 self.init_code = init_code 40 41class Enumeration(PairContainer): 42 def __init__(self, ident, pairs): 43 super(Enumeration, self).__init__(pairs) 44 self.ident = ident 45 | 1# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 2# Copyright (c) 2009 The Hewlett-Packard Development Company 3# All rights reserved. 4# 5# Redistribution and use in source and binary forms, with or without 6# modification, are permitted provided that the following conditions are 7# met: redistributions of source code must retain the above copyright 8# notice, this list of conditions and the following disclaimer; --- 29 unchanged lines hidden (view full) --- 38 self.type = type 39 self.init_code = init_code 40 41class Enumeration(PairContainer): 42 def __init__(self, ident, pairs): 43 super(Enumeration, self).__init__(pairs) 44 self.ident = ident 45 |
46class Method(object): 47 def __init__(self, return_type, param_types): 48 self.return_type = return_type 49 self.param_types = param_types 50 | |
51class Type(Symbol): 52 def __init__(self, table, ident, location, pairs, machine=None): 53 super(Type, self).__init__(table, ident, location, pairs) 54 self.c_ident = ident 55 self.abstract_ident = "" 56 if machine: 57 if self.isExternal or self.isPrimitive: 58 if "external_name" in self: --- 32 unchanged lines hidden (view full) --- 91 self["prefetcher"] = "yes" 92 93 self.isMachineType = (ident == "MachineType") 94 95 self.isStateDecl = ("state_decl" in self) 96 self.statePermPairs = [] 97 98 self.data_members = orderdict() | 46class Type(Symbol): 47 def __init__(self, table, ident, location, pairs, machine=None): 48 super(Type, self).__init__(table, ident, location, pairs) 49 self.c_ident = ident 50 self.abstract_ident = "" 51 if machine: 52 if self.isExternal or self.isPrimitive: 53 if "external_name" in self: --- 32 unchanged lines hidden (view full) --- 86 self["prefetcher"] = "yes" 87 88 self.isMachineType = (ident == "MachineType") 89 90 self.isStateDecl = ("state_decl" in self) 91 self.statePermPairs = [] 92 93 self.data_members = orderdict() |
99 100 # Methods | |
101 self.methods = {} | 94 self.methods = {} |
102 self.functions = {} 103 104 # Enums | |
105 self.enums = orderdict() 106 107 @property 108 def isPrimitive(self): 109 return "primitive" in self 110 @property 111 def isNetworkMessage(self): 112 return "networkmessage" in self --- 42 unchanged lines hidden (view full) --- 155 return '_'.join([name] + [ pt.c_ident for pt in param_type_vec ]) 156 157 def methodIdAbstract(self, name, param_type_vec): 158 return '_'.join([name] + [ pt.abstract_ident for pt in param_type_vec ]) 159 160 def statePermPairAdd(self, state_name, perm_name): 161 self.statePermPairs.append([state_name, perm_name]) 162 | 95 self.enums = orderdict() 96 97 @property 98 def isPrimitive(self): 99 return "primitive" in self 100 @property 101 def isNetworkMessage(self): 102 return "networkmessage" in self --- 42 unchanged lines hidden (view full) --- 145 return '_'.join([name] + [ pt.c_ident for pt in param_type_vec ]) 146 147 def methodIdAbstract(self, name, param_type_vec): 148 return '_'.join([name] + [ pt.abstract_ident for pt in param_type_vec ]) 149 150 def statePermPairAdd(self, state_name, perm_name): 151 self.statePermPairs.append([state_name, perm_name]) 152 |
163 def addMethod(self, name, return_type, param_type_vec): 164 ident = self.methodId(name, param_type_vec) 165 if ident in self.methods: 166 return False 167 168 self.methods[ident] = Method(return_type, param_type_vec) 169 return True 170 171 # Ideally either this function or the one above should exist. But 172 # methods and functions have different structures right now. 173 # Hence, these are different, at least for the time being. | |
174 def addFunc(self, func): 175 ident = self.methodId(func.ident, func.param_types) | 153 def addFunc(self, func): 154 ident = self.methodId(func.ident, func.param_types) |
176 if ident in self.functions: | 155 if ident in self.methods: |
177 return False 178 | 156 return False 157 |
179 self.functions[ident] = func | 158 self.methods[ident] = func |
180 return True 181 182 def addEnum(self, ident, pairs): 183 if ident in self.enums: 184 return False 185 186 self.enums[ident] = Enumeration(ident, pairs) 187 --- 186 unchanged lines hidden (view full) --- 374 assert self.isGlobal 375 init = " = %s" % (dm.init_code) 376 377 if "desc" in dm: 378 code('/** ${{dm["desc"]}} */') 379 380 code('$const${{dm.type.c_ident}} m_${{dm.ident}}$init;') 381 | 159 return True 160 161 def addEnum(self, ident, pairs): 162 if ident in self.enums: 163 return False 164 165 self.enums[ident] = Enumeration(ident, pairs) 166 --- 186 unchanged lines hidden (view full) --- 353 assert self.isGlobal 354 init = " = %s" % (dm.init_code) 355 356 if "desc" in dm: 357 code('/** ${{dm["desc"]}} */') 358 359 code('$const${{dm.type.c_ident}} m_${{dm.ident}}$init;') 360 |
382 # Prototypes for functions defined for the Type 383 for item in self.functions: 384 proto = self.functions[item].prototype | 361 # Prototypes for methods defined for the Type 362 for item in self.methods: 363 proto = self.methods[item].prototype |
385 if proto: 386 code('$proto') 387 388 code.dedent() 389 code('};') 390 391 code(''' 392inline std::ostream& --- 44 unchanged lines hidden (view full) --- 437 code('out << "Time = " << g_system_ptr->clockPeriod() * getTime() << " ";') 438 code.dedent() 439 440 # Trailer 441 code(''' 442 out << "]"; 443}''') 444 | 364 if proto: 365 code('$proto') 366 367 code.dedent() 368 code('};') 369 370 code(''' 371inline std::ostream& --- 44 unchanged lines hidden (view full) --- 416 code('out << "Time = " << g_system_ptr->clockPeriod() * getTime() << " ";') 417 code.dedent() 418 419 # Trailer 420 code(''' 421 out << "]"; 422}''') 423 |
445 # print the code for the functions in the type 446 for item in self.functions: 447 code(self.functions[item].generateCode()) | 424 # print the code for the methods in the type 425 for item in self.methods: 426 code(self.methods[item].generateCode()) |
448 449 code.write(path, "%s.cc" % self.c_ident) 450 451 def printEnumHH(self, path): 452 code = self.symtab.codeFormatter() 453 code(''' 454/** \\file ${{self.c_ident}}.hh 455 * --- 336 unchanged lines hidden --- | 427 428 code.write(path, "%s.cc" % self.c_ident) 429 430 def printEnumHH(self, path): 431 code = self.symtab.codeFormatter() 432 code(''' 433/** \\file ${{self.c_ident}}.hh 434 * --- 336 unchanged lines hidden --- |