00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "comma/parser/Descriptors.h"
00010 #include "comma/parser/ParseClient.h"
00011
00012 using namespace comma;
00013
00014
00015 void Node::dispose()
00016 {
00017 assert(state->rc != 0);
00018 if (--state->rc == 0) {
00019 if (isOwning())
00020 state->client.getPointer()->deleteNode(*this);
00021 delete state;
00022 }
00023 }
00024
00025 Node &Node::operator=(const Node &node)
00026 {
00027 if (state != node.state) {
00028 ++node.state->rc;
00029 dispose();
00030 state = node.state;
00031 }
00032 return *this;
00033 }
00034
00035 void Node::release()
00036 {
00037 unsigned prop = state->client.getInt();
00038 state->client.setInt(prop | NodeState::Released);
00039 }
00040
00041 bool Node::isOwning()
00042 {
00043 return !(state->client.getInt() & NodeState::Released);
00044 }
00045
00046 void Node::markInvalid()
00047 {
00048 unsigned prop = state->client.getInt();
00049 state->client.setInt(prop | NodeState::Invalid);
00050 }
00051
00052 void NodeVector::release()
00053 {
00054 for (iterator iter = begin(); iter != end(); ++iter)
00055 iter->release();
00056 }
00057
00058
00059 Descriptor::Descriptor(ParseClient *client, DescriptorKind kind)
00060 : kind (kind),
00061 invalidFlag(false),
00062 hasReturn(false),
00063 client(client),
00064 idInfo(0),
00065 location(0),
00066 returnType(client->getNullNode()) { }
00067
00068 void Descriptor::setReturnType(Node node)
00069 {
00070 assert(kind == DESC_Function &&
00071 "Only function descriptors have return types!");
00072 returnType = node;
00073 hasReturn = true;
00074 }
00075
00076 Node Descriptor::getReturnType()
00077 {
00078 assert(kind == DESC_Function &&
00079 "Only function descriptors have return types!");
00080 assert(hasReturn &&
00081 "Return type not set for this function descriptor!");
00082 return returnType;
00083 }
00084
00085 void Descriptor::clear()
00086 {
00087 kind = DESC_Empty;
00088 invalidFlag = false;
00089 hasReturn = false;
00090 idInfo = 0;
00091 location = 0;
00092 returnType = client->getNullNode();
00093 params.clear();
00094 }
00095
00096 void Descriptor::release()
00097 {
00098 returnType.release();
00099 params.release();
00100 }