00001 /* 00002 The lestes compiler suite 00003 Copyright (C) 2002, 2003, 2004, 2005 Miroslav Tichy 00004 Copyright (C) 2002, 2003, 2004, 2005 Petr Zika 00005 Copyright (C) 2002, 2003, 2004, 2005 Vojtech Hala 00006 Copyright (C) 2002, 2003, 2004, 2005 Jiri Kosina 00007 Copyright (C) 2002, 2003, 2004, 2005 Pavel Sanda 00008 Copyright (C) 2002, 2003, 2004, 2005 Jan Zouhar 00009 Copyright (C) 2002, 2003, 2004, 2005 Rudolf Thomas 00010 00011 This program is free software; you can redistribute it and/or modify 00012 it under the terms of the GNU General Public License as published by 00013 the Free Software Foundation; version 2 of the License. 00014 00015 This program is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU General Public License for more details. 00019 00020 See the full text of the GNU General Public License version 2, and 00021 the limitations in the file doc/LICENSE. 00022 00023 By accepting the license the licensee waives any and all claims 00024 against the copyright holder(s) related in whole or in part to the 00025 work, its use, and/or the inability to use it. 00026 00027 */ 00028 /*! \file 00029 \brief Conditional directive. 00030 00031 Definition of condition class representing conditional 00032 preprocessor directives. 00033 \author pt 00034 */ 00035 #include <lestes/common.hh> 00036 #include <lestes/equality.hh> 00037 #include <lestes/lang/cplus/lex/condition.hh> 00038 #include <lestes/std/source_location.hh> 00039 00040 package(lestes); 00041 package(lang); 00042 package(cplus); 00043 package(lex); 00044 00045 /*! 00046 Creates new condition, initializes with type and properties. 00047 \pre a_location != NULL 00048 \pre a_condition != COND_EMPTY 00049 \param a_location The location of usage. 00050 \param a_type The condition type. 00051 \param a_waiting Flag set when waiting for the true branch. 00052 \param a_active Flag set when the output was active in the level before this condition. 00053 \return New condition with given properties. 00054 */ 00055 condition::condition(type_type a_type, bool a_waiting, bool a_active, const ptr<source_location> &a_location): 00056 type((lassert(a_type != COND_EMPTY),a_type)), 00057 waiting(a_waiting), 00058 active(a_active), 00059 location(checked(a_location)) 00060 { 00061 } 00062 00063 /*! 00064 Creates empty condition, special value to simplify processing. 00065 Properties do not have any meaning for this value. 00066 \post type_get() == condition::COND_EMPTY 00067 \post active == true 00068 \return New empty condition. 00069 */ 00070 condition::condition(void): 00071 type(COND_EMPTY), 00072 waiting(false), 00073 active(true), 00074 location(NULL) 00075 { 00076 } 00077 00078 /*! 00079 Returns type of the condition. 00080 \return The type of the condition. 00081 */ 00082 condition::type_type condition::type_get(void) const 00083 { 00084 return type; 00085 } 00086 00087 /*! 00088 Returns the location of usage. 00089 \pre type != COND_EMPTY 00090 \return The usage source_location. 00091 */ 00092 ptr<source_location> condition::location_get(void) const 00093 { 00094 lassert(type != COND_EMPTY); 00095 return location; 00096 } 00097 00098 /*! 00099 Returns waiting flag. 00100 \pre type != COND_EMPTY 00101 \return true If waiting for true branch of the condition. 00102 */ 00103 bool condition::waiting_get(void) const 00104 { 00105 lassert(type != COND_EMPTY); 00106 return waiting; 00107 } 00108 00109 /*! 00110 Returns output activity flag. 00111 \return true If output is active in the previous level of conditionals. 00112 */ 00113 bool condition::active_get(void) const 00114 { 00115 return active; 00116 } 00117 00118 /*! 00119 Returns printable name of the condition. 00120 \pre type != COND_EMPTY 00121 \return The name to be used in error messages. 00122 */ 00123 lstring condition::name_get(void) const 00124 { 00125 lassert(type != COND_EMPTY); 00126 return condition_name[type]; 00127 } 00128 00129 /*! 00130 Tests equality to other condition. 00131 \param other The condition to compare with. 00132 \return true If both objects represent the same condition. 00133 */ 00134 bool condition::equals(const ptr<condition> &other) const 00135 { 00136 type_type t = other->type_get(); 00137 00138 // empty conditions do not have other fields 00139 if (t == COND_EMPTY) return is_equal(type_get(),COND_EMPTY); 00140 00141 return is_equal(type_get(),other->type_get()) && 00142 is_equal(waiting_get(),other->waiting_get()) && 00143 is_equal(active_get(),other->active_get()) && 00144 is_equal(location_get(),other->location_get()); 00145 } 00146 00147 /*! 00148 Marks the object. 00149 */ 00150 void condition::gc_mark(void) 00151 { 00152 location.gc_mark(); 00153 ::lestes::std::object::gc_mark(); 00154 } 00155 00156 /*! 00157 Returns empty condition, special value to simplify processing. 00158 \return New empty condition. 00159 */ 00160 ptr<condition> condition::create_empty(void) 00161 { 00162 return new condition(); 00163 } 00164 00165 /*! 00166 Returns new condition, initializes with type and properties. 00167 \param a_type The condition type. 00168 \param a_waiting Flag set when waiting for the true branch. 00169 \param a_active Flag set when the output was active in the level before this condition. 00170 \param a_location The location of usage. 00171 \return New condition with given properties. 00172 */ 00173 ptr<condition> condition::create(type_type a_type, bool a_waiting, bool a_active,const ptr<source_location> &a_location) 00174 { 00175 return new condition(a_type,a_waiting,a_active,a_location); 00176 } 00177 00178 /*! 00179 Printable names of the conditions for error reporting. 00180 */ 00181 lstring condition::condition_name[] = { 00182 "","#if","#ifdef","#ifndef","#elif","#else" 00183 }; 00184 00185 end_package(lex); 00186 end_package(cplus); 00187 end_package(lang); 00188 end_package(lestes); 00189 00190 /* vim: set ft=lestes : */
1.5.1-20070107