|
Qore Programming Language
0.8.3
|
00001 /* -*- mode: c++; indent-tabs-mode: nil -*- */ 00002 /* 00003 QoreNamespace.h 00004 00005 Qore Programming Language 00006 00007 Copyright 2003 - 2011 David Nichols 00008 00009 namespaces are children of a program object. there is a parse 00010 lock per program object to ensure that objects are added (or backed out) 00011 atomically per program object. All the objects referenced here should 00012 be safe to read & copied at all times. They will only be deleted when the 00013 program object is deleted (except the pending structures, which will be 00014 deleted any time there is a parse error, together with all other 00015 pending structures) 00016 00017 This library is free software; you can redistribute it and/or 00018 modify it under the terms of the GNU Lesser General Public 00019 License as published by the Free Software Foundation; either 00020 version 2.1 of the License, or (at your option) any later version. 00021 00022 This library is distributed in the hope that it will be useful, 00023 but WITHOUT ANY WARRANTY; without even the implied warranty of 00024 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00025 Lesser General Public License for more details. 00026 00027 You should have received a copy of the GNU Lesser General Public 00028 License along with this library; if not, write to the Free Software 00029 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00030 */ 00031 00032 #ifndef _QORE_QORENAMESPACE_H 00033 00034 #define _QORE_QORENAMESPACE_H 00035 00036 #include <string.h> 00037 #include <stdlib.h> 00038 00039 #include <string> 00040 00041 class RootQoreNamespace; 00042 class ConstantList; 00043 class QoreNamespaceList; 00044 class QoreClassList; 00045 class NamedScope; 00046 class MethodVariantBase; 00047 00049 00054 typedef QoreClass *(*q_ns_class_handler_t)(QoreNamespace *ns, const char *cname); 00055 00057 class QoreNamespace { 00058 friend class QoreNamespaceList; 00059 friend class RootQoreNamespace; 00060 friend class qore_ns_private; 00061 00062 protected: 00063 struct qore_ns_private *priv; // private implementation 00064 00065 DLLLOCAL AbstractQoreNode *parseMatchScopedConstantValue(const NamedScope *name, unsigned *matched, const QoreTypeInfo *&typeInfo) const; 00066 DLLLOCAL QoreClass *parseMatchScopedClass(const NamedScope *name, unsigned *matched); 00067 DLLLOCAL QoreClass *parseMatchScopedClassWithMethod(const NamedScope *nscope, unsigned *matched); 00068 DLLLOCAL QoreNamespace *parseMatchNamespace(const NamedScope *nscope, unsigned *matched) const; 00069 DLLLOCAL void assimilate(QoreNamespace *ns); 00070 DLLLOCAL QoreClass *parseFindLocalClass(const char *name) const; 00071 DLLLOCAL QoreNamespace *resolveNameScope(const NamedScope *name) const; 00072 DLLLOCAL AbstractQoreNode *getConstantValue(const char *name, const QoreTypeInfo *&typeInfo) const; 00073 DLLLOCAL QoreNamespace(const char *n, QoreClassList *ocl, ConstantList *cl, QoreNamespaceList *nnsl); 00074 00076 DLLLOCAL QoreNamespace(const QoreNamespace&); 00077 00079 DLLLOCAL QoreNamespace& operator=(const QoreNamespace&); 00080 00082 DLLLOCAL QoreNamespace(const QoreNamespace &old, int64 po); 00083 00084 public: 00086 00089 DLLEXPORT QoreNamespace(const char *n); 00090 00092 DLLEXPORT ~QoreNamespace(); 00093 00095 00101 DLLEXPORT void addConstant(const char *name, AbstractQoreNode *value); 00102 00104 00110 DLLEXPORT void addConstant(const char *name, AbstractQoreNode *value, const QoreTypeInfo *typeInfo); 00111 00113 00116 DLLEXPORT void addSystemClass(QoreClass *oc); 00117 00119 00124 DLLEXPORT void addInitialNamespace(QoreNamespace *ns); 00125 00127 00130 DLLEXPORT QoreNamespace *copy(int po) const; 00131 00133 00136 DLLEXPORT QoreNamespace *copy(int64 po = PO_DEFAULT) const; 00137 00139 00144 DLLEXPORT QoreHashNode *getClassInfo() const; 00145 00147 00152 DLLEXPORT QoreHashNode *getConstantInfo() const; 00153 00155 00161 DLLEXPORT QoreHashNode *getInfo() const; 00162 00164 00167 DLLEXPORT const char *getName() const; 00168 00170 00173 DLLEXPORT void addNamespace(QoreNamespace *ns); 00174 00176 00180 DLLEXPORT QoreNamespace *findCreateNamespacePath(const char *nspath); 00181 00183 00188 DLLEXPORT QoreClass *findLocalClass(const char *cname) const; 00189 00191 00195 DLLEXPORT QoreNamespace *findLocalNamespace(const char *nsname) const; 00196 00198 00201 DLLEXPORT void setClassHandler(q_ns_class_handler_t class_handler); 00202 00204 00206 DLLEXPORT const QoreNamespace *getParent() const; 00207 00209 DLLEXPORT void deleteData(ExceptionSink *xsink); 00210 00211 // parse-only interfaces are not exported 00212 DLLLOCAL QoreNamespace(); 00213 DLLLOCAL void addClass(const NamedScope *n, QoreClass *oc); 00214 00215 DLLLOCAL void parseAddConstant(const NamedScope &name, AbstractQoreNode *value); 00216 00217 DLLLOCAL void addClass(QoreClass *oc); 00218 DLLLOCAL void parseAddNamespace(QoreNamespace *ns); 00219 DLLLOCAL void parseInit(); 00220 DLLLOCAL void parseInitConstants(); 00221 DLLLOCAL void parseRollback(); 00222 DLLLOCAL void parseCommit(); 00223 DLLLOCAL void setName(const char *nme); 00224 00226 DLLLOCAL void purge(); 00227 }; 00228 00230 00234 class RootQoreNamespace : public QoreNamespace { 00235 protected: 00236 QoreNamespace *qoreNS; 00237 00238 DLLLOCAL QoreNamespace *rootResolveNamespace(const NamedScope *nscope); 00239 DLLLOCAL void addQoreNamespace(QoreNamespace *qns); 00240 // private constructor 00241 DLLLOCAL RootQoreNamespace(QoreClassList *ocl, ConstantList *cl, QoreNamespaceList *nnsl); 00242 // private constructor 00243 DLLLOCAL RootQoreNamespace(); 00244 DLLLOCAL QoreClass *rootFindScopedClass(const NamedScope *name, unsigned *matched); 00245 DLLLOCAL QoreClass *rootFindChangeClass(const char *name); 00246 DLLLOCAL AbstractQoreNode *rootFindScopedConstantValue(const NamedScope *name, unsigned *matched, const QoreTypeInfo *&typeInfo) const; 00247 00248 public: 00250 00253 DLLEXPORT QoreNamespace *rootGetQoreNamespace() const; 00254 00255 DLLLOCAL RootQoreNamespace(QoreNamespace *&QoreNS, int64 po = PO_DEFAULT); 00256 DLLLOCAL ~RootQoreNamespace(); 00257 DLLLOCAL RootQoreNamespace *copy(int64 po = PO_DEFAULT) const; 00258 DLLLOCAL QoreClass *rootFindClass(const char *name) const; 00259 DLLLOCAL void rootAddClass(const NamedScope *name, QoreClass *oc); 00260 DLLLOCAL void rootAddConstant(const NamedScope &name, AbstractQoreNode *value); 00261 DLLLOCAL AbstractQoreNode *findConstantValue(const NamedScope *name, const QoreTypeInfo *&typeInfo) const; 00262 DLLLOCAL AbstractQoreNode *findConstantValue(const char *name, const QoreTypeInfo *&typeInfo) const; 00263 DLLLOCAL QoreClass *parseFindClass(const char *name) const; 00264 DLLLOCAL QoreClass *parseFindScopedClass(const NamedScope *name); 00265 DLLLOCAL QoreClass *parseFindScopedClassWithMethod(const NamedScope *name); 00266 // returns 0 for success, non-zero for error 00267 DLLLOCAL int resolveBareword(AbstractQoreNode **, const QoreTypeInfo *&) const; 00268 // returns 0 for success, non-zero for error (parse exception thrown) 00269 DLLLOCAL int resolveScopedReference(AbstractQoreNode **, const QoreTypeInfo *&) const; 00270 // does not throw parse exceptions 00271 DLLLOCAL AbstractQoreNode *resolveScopedReference(const NamedScope &ns, unsigned &m, const QoreTypeInfo *&typeInfo) const; 00272 // returns 0 for success, non-zero for error 00273 DLLLOCAL int addMethodToClass(const NamedScope *name, MethodVariantBase *qcmethod, bool static_flag); 00274 DLLLOCAL QoreClass *rootFindScopedClassWithMethod(const NamedScope *nscope, unsigned *matched); 00275 DLLLOCAL AbstractQoreNode *rootFindConstantValue(const char *name, const QoreTypeInfo *&typeInfo) const; 00276 }; 00277 00278 #endif // QORE_NAMESPACE_H