00001 /* 00002 Copyright (c) 2009, National Institute of Advanced Industrial Science 00003 and Technology. All rights reserved. 00004 00005 Redistribution and use in source and binary forms, with or without 00006 modification, are permitted provided that the following conditions are 00007 met: 00008 00009 * Redistributions of source code must retain the above copyright 00010 notice, this list of conditions and the following disclaimer. 00011 00012 * Redistributions in binary form must reproduce the above copyright 00013 notice, this list of conditions and the following disclaimer in 00014 the documentation and/or other materials provided with the 00015 distribution. 00016 00017 * Neither the name of Fixstars Corporation nor the names of its 00018 contributors may be used to endorse or promote products derived 00019 from this software without specific prior written permission. 00020 00021 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00024 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00025 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00026 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00027 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00028 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00029 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00030 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00031 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00032 */ 00033 00034 #ifndef CFRONT_VALUE_NODE_HPP 00035 #define CFRONT_VALUE_NODE_HPP 00036 00037 #include "LocationNode.hpp" 00038 #include "BasicType.hpp" 00039 #include "NameDescription.hpp" 00040 #include "Environment.hpp" 00041 00042 namespace cfront { 00043 00048 union Value { 00050 struct DeclSpec { 00051 cfront::Type* type; 00052 cfront::NameDescription::StorageClassSpecTag ssTag; 00053 } declSpec; 00054 00056 cfront::QualFlags qualFlags; 00057 00059 const cfront::Type* type; 00060 00062 struct SignedValue { 00063 const cfront::Type* type; 00064 long long ival; 00065 } signedValue; 00066 00068 struct UnsignedValue { 00069 const cfront::Type* type; 00070 unsigned long long ival; 00071 } unsignedValue; 00072 00074 struct StringValue { 00075 const cfront::Type* type; 00076 std::string* sval; 00077 } stringValue; 00078 00080 struct IdentValue { 00081 const cfront::Type* type; 00082 bool isFree; 00083 } identValue; 00084 }; 00085 00086 00087 class ValueNode; 00088 00089 typedef ANTLR_USE_NAMESPACE(antlr)ASTRefCount<ValueNode> RefValueNode; 00090 00094 class ValueNode : public LocationNode { 00095 public: 00096 00098 ValueNode(const ValueNode& other) 00099 : LocationNode(other), value_(other.value_) {} 00100 00102 ValueNode() : LocationNode() 00103 { 00104 value_.declSpec.type = NULL; 00105 value_.declSpec.ssTag = cfront::NameDescription::SS_NONE; 00106 } 00107 virtual ~ValueNode() {} 00108 00109 Value getValue() const 00110 { 00111 return value_; 00112 } 00113 00114 void setValue(Value& value) 00115 { 00116 value_ = value; 00117 } 00118 00119 Value& getValueRef() { 00120 return value_; 00121 } 00122 00123 void addOptLocation(const RefValueNode& other) 00124 { 00125 LocationNode::addOptLocation(RefLocationNode(other)); 00126 } 00127 00128 virtual void initialize(int t, const ANTLR_USE_NAMESPACE(std)string& txt) 00129 { 00130 LocationNode::initialize(t, txt); 00131 value_.declSpec.type = NULL; 00132 value_.declSpec.ssTag = cfront::NameDescription::SS_NONE; 00133 } 00134 virtual void initialize(ANTLR_USE_NAMESPACE(antlr)RefToken t) 00135 { 00136 LocationNode::initialize(t); 00137 value_.declSpec.type = NULL; 00138 value_.declSpec.ssTag = cfront::NameDescription::SS_NONE; 00139 } 00140 virtual void initialize(RefValueNode ast) 00141 { 00142 LocationNode::initialize(RefLocationNode(ast)); 00143 value_ = ast->getValue(); 00144 } 00145 00147 virtual ANTLR_USE_NAMESPACE(antlr)RefAST clone() 00148 { 00149 return ANTLR_USE_NAMESPACE(antlr)RefAST(new ValueNode(*this)); 00150 } 00151 static ANTLR_USE_NAMESPACE(antlr)RefAST factory() 00152 { 00153 return ANTLR_USE_NAMESPACE(antlr)RefAST(RefValueNode(new ValueNode())); 00154 } 00155 00156 protected: 00157 Value value_; 00158 }; 00159 00160 } // namespace cfront 00161 00162 #endif 00163 00164 /* 00165 * Local Variables: 00166 * mode: C++ 00167 * c-basic-offset: 4 00168 * indent-tabs-mode: nil 00169 * End: 00170 */