LocalVariableAST.py (7839:9e556fb25900) | LocalVariableAST.py (8085:d1eb504fd302) |
---|---|
1# 2# Copyright (c) 2011 Mark D. Hill and David A. Wood 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; --- 16 unchanged lines hidden (view full) --- 25# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27# 28 29from slicc.ast.StatementAST import StatementAST 30from slicc.symbols import Var 31 32class LocalVariableAST(StatementAST): | 1# 2# Copyright (c) 2011 Mark D. Hill and David A. Wood 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; --- 16 unchanged lines hidden (view full) --- 25# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27# 28 29from slicc.ast.StatementAST import StatementAST 30from slicc.symbols import Var 31 32class LocalVariableAST(StatementAST): |
33 def __init__(self, slicc, type_ast, ident): | 33 def __init__(self, slicc, type_ast, ident, pointer = False): |
34 super(LocalVariableAST, self).__init__(slicc) 35 self.type_ast = type_ast 36 self.ident = ident | 34 super(LocalVariableAST, self).__init__(slicc) 35 self.type_ast = type_ast 36 self.ident = ident |
37 self.pointer = pointer |
|
37 38 def __repr__(self): 39 return "[LocalVariableAST: %r %r]" % (self.type_ast, self.ident) 40 41 @property 42 def name(self): 43 return self.var_name 44 45 def generate(self, code): 46 type = self.type_ast.type; 47 ident = "%s" % self.ident; 48 49 # Add to symbol table 50 v = Var(self.symtab, self.ident, self.location, type, ident, 51 self.pairs) 52 self.symtab.newSymbol(v) | 38 39 def __repr__(self): 40 return "[LocalVariableAST: %r %r]" % (self.type_ast, self.ident) 41 42 @property 43 def name(self): 44 return self.var_name 45 46 def generate(self, code): 47 type = self.type_ast.type; 48 ident = "%s" % self.ident; 49 50 # Add to symbol table 51 v = Var(self.symtab, self.ident, self.location, type, ident, 52 self.pairs) 53 self.symtab.newSymbol(v) |
53 code += "%s* %s" % (type.c_ident, ident) | 54 if self.pointer or str(type) == "TBE" or ( 55 "interface" in type and type["interface"] == "AbstractCacheEntry"): 56 code += "%s* %s" % (type.c_ident, ident) 57 else: 58 code += "%s %s" % (type.c_ident, ident) |
54 return type | 59 return type |