TypeFieldStateAST.py revision 6690
12817Sksewell@umich.edu# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
22817Sksewell@umich.edu# Copyright (c) 2009 The Hewlett-Packard Development Company
32817Sksewell@umich.edu# All rights reserved.
42817Sksewell@umich.edu#
52817Sksewell@umich.edu# Redistribution and use in source and binary forms, with or without
62817Sksewell@umich.edu# modification, are permitted provided that the following conditions are
72817Sksewell@umich.edu# met: redistributions of source code must retain the above copyright
82817Sksewell@umich.edu# notice, this list of conditions and the following disclaimer;
92817Sksewell@umich.edu# redistributions in binary form must reproduce the above copyright
102817Sksewell@umich.edu# notice, this list of conditions and the following disclaimer in the
112817Sksewell@umich.edu# documentation and/or other materials provided with the distribution;
122817Sksewell@umich.edu# neither the name of the copyright holders nor the names of its
132817Sksewell@umich.edu# contributors may be used to endorse or promote products derived from
142817Sksewell@umich.edu# this software without specific prior written permission.
152817Sksewell@umich.edu#
162817Sksewell@umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172817Sksewell@umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182817Sksewell@umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192817Sksewell@umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202817Sksewell@umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212817Sksewell@umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222817Sksewell@umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232817Sksewell@umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242817Sksewell@umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252817Sksewell@umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262817Sksewell@umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272817Sksewell@umich.edu
282817Sksewell@umich.edufrom slicc.ast.TypeFieldAST import TypeFieldAST
294202Sbinkertn@umich.edufrom slicc.symbols import Event, State
302817Sksewell@umich.edu
312817Sksewell@umich.educlass TypeFieldEnumAST(TypeFieldAST):
322817Sksewell@umich.edu    def __init__(self, slicc, field_id, pairs_ast):
334202Sbinkertn@umich.edu        super(TypeFieldEnumAST, self).__init__(slicc, pairs_ast)
342817Sksewell@umich.edu
355192Ssaidi@eecs.umich.edu        self.field_id = field_id
365192Ssaidi@eecs.umich.edu        self.pairs_ast = pairs_ast
375192Ssaidi@eecs.umich.edu
385192Ssaidi@eecs.umich.edu    def __repr__(self):
395192Ssaidi@eecs.umich.edu        return "[TypeFieldEnum: %r]" % self.field_id
405192Ssaidi@eecs.umich.edu
415192Ssaidi@eecs.umich.edu    def generate(self, type):
425192Ssaidi@eecs.umich.edu        # Add enumeration
435192Ssaidi@eecs.umich.edu        if not type.enumAdd(self.field_id, self.pairs_ast.pairs):
445192Ssaidi@eecs.umich.edu            self.error("Duplicate enumeration: %s:%s" % (type, self.field_id))
454202Sbinkertn@umich.edu
464486Sbinkertn@umich.edu        # Fill machine info
474486Sbinkertn@umich.edu        machine = self.symtab.state_machine
484486Sbinkertn@umich.edu
494486Sbinkertn@umich.edu        if str(type) == "State":
504202Sbinkertn@umich.edu            if not machine:
514202Sbinkertn@umich.edu                self.error("State declaration not part of a machine.")
524202Sbinkertn@umich.edu            s = State(self.symtab, self.field_id, self.location, self.pairs)
534202Sbinkertn@umich.edu            machine.addState(s)
545597Sgblack@eecs.umich.edu
554202Sbinkertn@umich.edu        if str(type) == "Event":
565597Sgblack@eecs.umich.edu            if not machine:
574202Sbinkertn@umich.edu                self.error("Event declaration not part of a machine.")
584202Sbinkertn@umich.edu            e = Event(self.symtab, self.field_id, self.location, self.pairs)
594202Sbinkertn@umich.edu            machine.addEvent(e)
604202Sbinkertn@umich.edu