TypeFieldEnumAST.py revision 9298
110478SAndrew.Bardsley@arm.com# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 210478SAndrew.Bardsley@arm.com# Copyright (c) 2009 The Hewlett-Packard Development Company 310478SAndrew.Bardsley@arm.com# All rights reserved. 410478SAndrew.Bardsley@arm.com# 510478SAndrew.Bardsley@arm.com# Redistribution and use in source and binary forms, with or without 610478SAndrew.Bardsley@arm.com# modification, are permitted provided that the following conditions are 710478SAndrew.Bardsley@arm.com# met: redistributions of source code must retain the above copyright 810478SAndrew.Bardsley@arm.com# notice, this list of conditions and the following disclaimer; 910478SAndrew.Bardsley@arm.com# redistributions in binary form must reproduce the above copyright 1010478SAndrew.Bardsley@arm.com# notice, this list of conditions and the following disclaimer in the 1110478SAndrew.Bardsley@arm.com# documentation and/or other materials provided with the distribution; 1210478SAndrew.Bardsley@arm.com# neither the name of the copyright holders nor the names of its 1310478SAndrew.Bardsley@arm.com# contributors may be used to endorse or promote products derived from 1410478SAndrew.Bardsley@arm.com# this software without specific prior written permission. 1510478SAndrew.Bardsley@arm.com# 1610478SAndrew.Bardsley@arm.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1710478SAndrew.Bardsley@arm.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1810478SAndrew.Bardsley@arm.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1910478SAndrew.Bardsley@arm.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2010478SAndrew.Bardsley@arm.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2110478SAndrew.Bardsley@arm.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2210478SAndrew.Bardsley@arm.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2310478SAndrew.Bardsley@arm.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2410478SAndrew.Bardsley@arm.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2510478SAndrew.Bardsley@arm.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2610478SAndrew.Bardsley@arm.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2710478SAndrew.Bardsley@arm.com 2810478SAndrew.Bardsley@arm.comfrom slicc.ast.TypeFieldAST import TypeFieldAST 2910478SAndrew.Bardsley@arm.comfrom slicc.symbols import Event, State, RequestType 3010478SAndrew.Bardsley@arm.com 3110478SAndrew.Bardsley@arm.comclass TypeFieldEnumAST(TypeFieldAST): 3210478SAndrew.Bardsley@arm.com def __init__(self, slicc, field_id, pairs_ast): 3310478SAndrew.Bardsley@arm.com super(TypeFieldEnumAST, self).__init__(slicc, pairs_ast) 3410478SAndrew.Bardsley@arm.com 3510478SAndrew.Bardsley@arm.com self.field_id = field_id 3610478SAndrew.Bardsley@arm.com self.pairs_ast = pairs_ast 3710478SAndrew.Bardsley@arm.com 3811817SChristian.Menard@tu-dresden.de def __repr__(self): 3910478SAndrew.Bardsley@arm.com return "[TypeFieldEnum: %r]" % self.field_id 4010478SAndrew.Bardsley@arm.com 4111817SChristian.Menard@tu-dresden.de def generate(self, type): 4210478SAndrew.Bardsley@arm.com if str(type) == "State": 4310478SAndrew.Bardsley@arm.com self.error("States must in a State Declaration, not a normal enum.") 4410478SAndrew.Bardsley@arm.com 4510478SAndrew.Bardsley@arm.com # Add enumeration 4610478SAndrew.Bardsley@arm.com if not type.addEnum(self.field_id, self.pairs_ast.pairs): 4710478SAndrew.Bardsley@arm.com self.error("Duplicate enumeration: %s:%s" % (type, self.field_id)) 4810478SAndrew.Bardsley@arm.com 4910478SAndrew.Bardsley@arm.com # Fill machine info 5010478SAndrew.Bardsley@arm.com machine = self.symtab.state_machine 5110478SAndrew.Bardsley@arm.com 5210478SAndrew.Bardsley@arm.com if str(type) == "Event": 5310478SAndrew.Bardsley@arm.com if not machine: 5410478SAndrew.Bardsley@arm.com self.error("Event declaration not part of a machine.") 5511817SChristian.Menard@tu-dresden.de e = Event(self.symtab, self.field_id, self.location, self.pairs) 5611817SChristian.Menard@tu-dresden.de machine.addEvent(e) 57 58 if str(type) == "RequestType": 59 if not machine: 60 self.error("RequestType declaration not part of a machine.") 61 s = RequestType(self.symtab, self.field_id, self.location, 62 self.pairs) 63 machine.addRequestType(s) 64