Type.py (9219:258753d3bc47) Type.py (9298:9a087e046c58)
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;

--- 93 unchanged lines hidden (view full) ---

102
103 self.isStateDecl = ("state_decl" in self)
104 self.statePermPairs = []
105
106 self.data_members = orderdict()
107
108 # Methods
109 self.methods = {}
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;

--- 93 unchanged lines hidden (view full) ---

102
103 self.isStateDecl = ("state_decl" in self)
104 self.statePermPairs = []
105
106 self.data_members = orderdict()
107
108 # Methods
109 self.methods = {}
110 self.functions = {}
110
111 # Enums
112 self.enums = orderdict()
113
114 @property
115 def isPrimitive(self):
116 return "primitive" in self
117 @property

--- 20 unchanged lines hidden (view full) ---

138 @property
139 def isGlobal(self):
140 return "global" in self
141 @property
142 def isInterface(self):
143 return "interface" in self
144
145 # Return false on error
111
112 # Enums
113 self.enums = orderdict()
114
115 @property
116 def isPrimitive(self):
117 return "primitive" in self
118 @property

--- 20 unchanged lines hidden (view full) ---

139 @property
140 def isGlobal(self):
141 return "global" in self
142 @property
143 def isInterface(self):
144 return "interface" in self
145
146 # Return false on error
146 def dataMemberAdd(self, ident, type, pairs, init_code):
147 def addDataMember(self, ident, type, pairs, init_code):
147 if ident in self.data_members:
148 return False
149
150 member = DataMember(ident, type, pairs, init_code)
151 self.data_members[ident] = member
152
153 return True
154

--- 4 unchanged lines hidden (view full) ---

159 return '_'.join([name] + [ pt.c_ident for pt in param_type_vec ])
160
161 def methodIdAbstract(self, name, param_type_vec):
162 return '_'.join([name] + [ pt.abstract_ident for pt in param_type_vec ])
163
164 def statePermPairAdd(self, state_name, perm_name):
165 self.statePermPairs.append([state_name, perm_name])
166
148 if ident in self.data_members:
149 return False
150
151 member = DataMember(ident, type, pairs, init_code)
152 self.data_members[ident] = member
153
154 return True
155

--- 4 unchanged lines hidden (view full) ---

160 return '_'.join([name] + [ pt.c_ident for pt in param_type_vec ])
161
162 def methodIdAbstract(self, name, param_type_vec):
163 return '_'.join([name] + [ pt.abstract_ident for pt in param_type_vec ])
164
165 def statePermPairAdd(self, state_name, perm_name):
166 self.statePermPairs.append([state_name, perm_name])
167
167 def methodAdd(self, name, return_type, param_type_vec):
168 def addMethod(self, name, return_type, param_type_vec):
168 ident = self.methodId(name, param_type_vec)
169 if ident in self.methods:
170 return False
171
172 self.methods[ident] = Method(return_type, param_type_vec)
173 return True
174
169 ident = self.methodId(name, param_type_vec)
170 if ident in self.methods:
171 return False
172
173 self.methods[ident] = Method(return_type, param_type_vec)
174 return True
175
175 def enumAdd(self, ident, pairs):
176 # Ideally either this function or the one above should exist. But
177 # methods and functions have different structures right now.
178 # Hence, these are different, at least for the time being.
179 def addFunc(self, func):
180 ident = self.methodId(func.ident, func.param_types)
181 if ident in self.functions:
182 return False
183
184 self.functions[ident] = func
185 return True
186
187 def addEnum(self, ident, pairs):
176 if ident in self.enums:
177 return False
178
179 self.enums[ident] = Enumeration(ident, pairs)
180
181 # Add default
182 if "default" not in self:
183 self["default"] = "%s_NUM" % self.c_ident

--- 179 unchanged lines hidden (view full) ---

363 assert self.isGlobal
364 init = " = %s" % (dm.init_code)
365
366 if "desc" in dm:
367 code('/** ${{dm["desc"]}} */')
368
369 code('$const${{dm.type.c_ident}} m_${{dm.ident}}$init;')
370
188 if ident in self.enums:
189 return False
190
191 self.enums[ident] = Enumeration(ident, pairs)
192
193 # Add default
194 if "default" not in self:
195 self["default"] = "%s_NUM" % self.c_ident

--- 179 unchanged lines hidden (view full) ---

375 assert self.isGlobal
376 init = " = %s" % (dm.init_code)
377
378 if "desc" in dm:
379 code('/** ${{dm["desc"]}} */')
380
381 code('$const${{dm.type.c_ident}} m_${{dm.ident}}$init;')
382
383 # Prototypes for functions defined for the Type
384 for item in self.functions:
385 proto = self.functions[item].prototype
386 if proto:
387 code('$proto')
388
371 code.dedent()
372 code('};')
373
374 code('''
375inline std::ostream&
376operator<<(std::ostream& out, const ${{self.c_ident}}& obj)
377{
378 obj.print(out);

--- 39 unchanged lines hidden (view full) ---

418 code('out << "Time = " << g_system_ptr->clockPeriod() * getTime() << " ";')
419 code.dedent()
420
421 # Trailer
422 code('''
423 out << "]";
424}''')
425
389 code.dedent()
390 code('};')
391
392 code('''
393inline std::ostream&
394operator<<(std::ostream& out, const ${{self.c_ident}}& obj)
395{
396 obj.print(out);

--- 39 unchanged lines hidden (view full) ---

436 code('out << "Time = " << g_system_ptr->clockPeriod() * getTime() << " ";')
437 code.dedent()
438
439 # Trailer
440 code('''
441 out << "]";
442}''')
443
444 # print the code for the functions in the type
445 for item in self.functions:
446 code(self.functions[item].generateCode())
447
426 code.write(path, "%s.cc" % self.c_ident)
427
428 def printEnumHH(self, path):
429 code = self.symtab.codeFormatter()
430 code('''
431/** \\file ${{self.c_ident}}.hh
432 *
433 * Auto generated C++ code started by $__file__:$__line__

--- 345 unchanged lines hidden ---
448 code.write(path, "%s.cc" % self.c_ident)
449
450 def printEnumHH(self, path):
451 code = self.symtab.codeFormatter()
452 code('''
453/** \\file ${{self.c_ident}}.hh
454 *
455 * Auto generated C++ code started by $__file__:$__line__

--- 345 unchanged lines hidden ---