C-Breeze
C Compiler Infrastructure

[ Project home page]
Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

dismantle-label.cc

Go to the documentation of this file.
00001 // $Id: dismantle-label.cc,v 1.2 2003/08/07 23:13:43 pnav Exp $
00002 // ----------------------------------------------------------------------
00003 //
00004 //  C-Breeze
00005 //  C Compiler Framework
00006 // 
00007 //  Copyright (c) 2000 University of Texas at Austin
00008 // 
00009 //  Samuel Z. Guyer
00010 //  Daniel A. Jimenez
00011 //  Calvin Lin
00012 //  Adam Brown
00013 // 
00014 //  Permission is hereby granted, free of charge, to any person
00015 //  obtaining a copy of this software and associated documentation
00016 //  files (the "Software"), to deal in the Software without
00017 //  restriction, including without limitation the rights to use, copy,
00018 //  modify, merge, publish, distribute, sublicense, and/or sell copies
00019 //  of the Software, and to permit persons to whom the Software is
00020 //  furnished to do so, subject to the following conditions:
00021 //  
00022 //  The above copyright notice and this permission notice shall be
00023 //  included in all copies or substantial portions of the Software.
00024 //  
00025 //  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00026 //  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00027 //  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00028 //  NONINFRINGEMENT.  IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT
00029 //  AUSTIN BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
00030 //  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
00031 //  OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00032 //  THE SOFTWARE.
00033 //
00034 //  We acknowledge the C-to-C Translator from MIT Laboratory for
00035 //  Computer Science for inspiring parts of the C-Breeze design.
00036 //
00037 // ----------------------------------------------------------------------
00038 //
00039 // dismantle-label.cc
00040 //
00041 
00042 #include "c_breeze.h"
00043 #include "dismantle.h"
00044 
00045 LabelDismantle::LabelDismantle(void):
00046   Changer(Preorder, Subtree, false)
00047 {}
00048 
00049 // All labels in dismantled code should label empty statements.
00050 // We enforce this by turning any label which labels a non-empty statement
00051 // into a block with the label (labeling an empty statement) and the original
00052 // statement that was labeled.  This extra block will later be removed when
00053 // we 'flatten' the dismantled code.
00054 //
00055 // label: { ... }
00056 // =>
00057 // {
00058 //   label: { ; }
00059 //   { ... }
00060 // }
00061 
00062 Node * LabelDismantle::at_label(labelNode * the_label, Order ord) {
00063   bool empty = true;
00064   blockNode * label_block = the_label->stmt();
00065   for( stmt_list_p p = label_block->stmts().begin(); 
00066        empty && p != label_block->stmts().end();
00067        p++ ) {
00068     if ((*p)->typ() != Expr )
00069       empty = false;
00070     else {
00071       exprstmtNode * tmp = (exprstmtNode *) *p;
00072       if ( tmp->expr() ) // expr != NULL => not empty
00073         empty = false;
00074     }
00075   }
00076   if ( empty )  // stmt/block was empty stmt
00077     return the_label; // no change necessary
00078   blockNode * label_stmt = the_label->get_stmt();
00079   blockNode * new_block = new blockNode(&label_stmt->decls(),
00080                                         &label_stmt->stmts(),
00081                                         the_label->coord());
00082   the_label->stmt(DismantleUtil::empty_block());
00083   new_block->stmts().push_front(the_label);
00084   return new_block;
00085 }

Generated on August 27, 2003
Back to the C-Breeze home page