00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include <string.h>
00017 #include <ctype.h>
00018
00019 #include "../sexpress/shashtbl.hpp"
00020
00021 #include "spkghsh.hpp"
00022
00024
00025
00026 IntelibTypeId
00027 SExpressionHashPackage::TypeId(&SExpressionHashTable::TypeId, false);
00028
00029
00030
00031
00032 SExpressionHashPackage::SExpressionHashPackage()
00033 : SExpressionHashTable(TypeId)
00034 {}
00035
00036 SExpressionHashPackage::SExpressionHashPackage(const SHashPackage& par)
00037 : SExpressionHashTable(TypeId), parent(par)
00038 {}
00039
00040 SExpressionHashPackage::SExpressionHashPackage(const IntelibTypeId& tid)
00041 : SExpressionHashTable(tid)
00042 {}
00043
00044 SExpressionHashPackage::SExpressionHashPackage(const IntelibTypeId& tid,
00045 const SHashPackage& par)
00046 : SExpressionHashTable(tid), parent(par)
00047 {}
00048
00049 SExpressionHashPackage::~SExpressionHashPackage()
00050 {}
00051
00052 bool SExpressionHashPackage::Import(const SReference &ref,
00053 const char *symbname,
00054 bool safe)
00055 {
00056 SExpressionLabel *symb = ref.DynamicCastGetPtr<SExpressionLabel>();
00057 INTELIB_ASSERT(symb, IntelibX_not_a_label(ref));
00058
00059 const char *name = symbname ? symbname : symb->GetName();
00060
00061 if(safe) {
00062 return SafeAddItem(name, ref);
00063 } else {
00064 AddItem(name, ref);
00065 return true;
00066 }
00067 }
00068
00069 SReference SExpressionHashPackage::Intern(const char *name)
00070 {
00071 SReference ret = FindSymbol(name);
00072 if(ret.GetPtr() == EmptySlotMark.GetPtr()) {
00073
00074 ret = CreateNewSymbolObject(name);
00075 AddItem(name, ret);
00076 }
00077 return ret;
00078 }
00079
00080 SReference SExpressionHashPackage::FindSymbol(const char *name)
00081 {
00082 SReference tmp = FindItem(name);
00083 if(tmp.GetPtr() == EmptySlotMark.GetPtr() && parent.GetPtr()) {
00084 return parent->FindSymbol(name);
00085 } else {
00086 return tmp;
00087 }
00088 }
00089
00090 #if 0
00091 SReference SExpressionHashPackage::GetAllSymbols() const
00092 {
00093 SReference res(*PTheEmptyList);
00094 Iterator it(*this);
00095 SReference r = it.GetNext();
00096 while(r.GetPtr()) {
00097 res = SReference(r.Cdr(), res);
00098 r = it.GetNext();
00099 }
00100 }
00101 #endif
00102
00103 SReference SExpressionHashPackage::MakeSymbol(const char *name)
00104 {
00105 return Intern(name);
00106 }
00107
00108 SString SExpressionHashPackage::TextRepresentation() const
00109 {
00110 return SString("#<PACKAGE>");
00111 }
00112
00113
00114 SReference SExpressionHashPackage::CreateNewSymbolObject(const char *nm) const
00115 {
00116 return SReference(new SExpressionLabel(nm));
00117 }
00118
00120
00121
00122 IntelibX_not_a_package::
00123 IntelibX_not_a_package(SReference a_param)
00124 : IntelibX("Not a package", a_param) {}
00125
00126 IntelibX_package_conflict::
00127 IntelibX_package_conflict(SReference a_param)
00128 : IntelibX("Name conflict within a package", a_param) {}