TypeFieldEnumAST.py revision 6657
112954Sgabeblack@google.com# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 212954Sgabeblack@google.com# Copyright (c) 2009 The Hewlett-Packard Development Company 312954Sgabeblack@google.com# All rights reserved. 412954Sgabeblack@google.com# 512954Sgabeblack@google.com# Redistribution and use in source and binary forms, with or without 612954Sgabeblack@google.com# modification, are permitted provided that the following conditions are 712954Sgabeblack@google.com# met: redistributions of source code must retain the above copyright 812954Sgabeblack@google.com# notice, this list of conditions and the following disclaimer; 912954Sgabeblack@google.com# redistributions in binary form must reproduce the above copyright 1012954Sgabeblack@google.com# notice, this list of conditions and the following disclaimer in the 1112954Sgabeblack@google.com# documentation and/or other materials provided with the distribution; 1212954Sgabeblack@google.com# neither the name of the copyright holders nor the names of its 1312954Sgabeblack@google.com# contributors may be used to endorse or promote products derived from 1412954Sgabeblack@google.com# this software without specific prior written permission. 1512954Sgabeblack@google.com# 1612954Sgabeblack@google.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1712954Sgabeblack@google.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1812954Sgabeblack@google.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1912954Sgabeblack@google.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2012954Sgabeblack@google.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2112954Sgabeblack@google.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2212954Sgabeblack@google.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2312954Sgabeblack@google.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2412954Sgabeblack@google.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2512954Sgabeblack@google.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2612954Sgabeblack@google.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2712954Sgabeblack@google.com 2812954Sgabeblack@google.comfrom slicc.ast.TypeFieldAST import TypeFieldAST 2912954Sgabeblack@google.comfrom slicc.symbols import Event, State 3012954Sgabeblack@google.com 3112954Sgabeblack@google.comclass TypeFieldEnumAST(TypeFieldAST): 3212954Sgabeblack@google.com def __init__(self, slicc, field_id, pairs_ast): 3312954Sgabeblack@google.com super(TypeFieldEnumAST, self).__init__(slicc, pairs_ast) 3412954Sgabeblack@google.com 3512954Sgabeblack@google.com self.field_id = field_id 3612954Sgabeblack@google.com self.pairs_ast = pairs_ast 3713059Sgabeblack@google.com 3813059Sgabeblack@google.com def __repr__(self): 3913059Sgabeblack@google.com return "[TypeFieldEnum: %r]" % self.field_id 4013059Sgabeblack@google.com 4113059Sgabeblack@google.com def generate(self, type): 4213059Sgabeblack@google.com # Add enumeration 4313059Sgabeblack@google.com if not type.enumAdd(self.field_id, self.pairs_ast.pairs): 4413059Sgabeblack@google.com error("Duplicate enumeration: %s:%s" % (type, self.field_id)) 4513059Sgabeblack@google.com 4613059Sgabeblack@google.com # Fill machine info 4712954Sgabeblack@google.com machine = self.symtab.state_machine 4812954Sgabeblack@google.com 4912954Sgabeblack@google.com if str(type) == "State": 5012954Sgabeblack@google.com if not machine: 5112954Sgabeblack@google.com error("State declaration not part of a machine.") 5212954Sgabeblack@google.com s = State(self.symtab, self.field_id, self.location, self.pairs) 5312954Sgabeblack@google.com machine.addState(s) 5412954Sgabeblack@google.com 5512954Sgabeblack@google.com if str(type) == "Event": 5612954Sgabeblack@google.com if not machine: 5712954Sgabeblack@google.com error("Event declaration not part of a machine.") 5812954Sgabeblack@google.com e = Event(self.symtab, self.field_id, self.location, self.pairs) 5912954Sgabeblack@google.com machine.addEvent(e) 6013059Sgabeblack@google.com