00001 /* 00002 * lib/sourcepos/sourcefile.h 00003 * 00004 * Classes for sophisticated source position (file/line/lpos, 00005 * include hierarchy) handling. 00006 * 00007 * Copyright (c) 2003--2004 by Wolfgang Wieser ] wwieser (a) gmx <*> de [ 00008 * 00009 * This file may be distributed and/or modified under the terms of the 00010 * GNU General Public License version 2 as published by the Free Software 00011 * Foundation. (See COPYING.GPL for details.) 00012 * 00013 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00014 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00015 * 00016 */ 00017 00018 #ifndef _LIB_SOURCEPOS_SOURCEFILE_H_ 00019 #define _LIB_SOURCEPOS_SOURCEFILE_H_ 1 00020 00030 #include <lib/sconfig.h> /* MUST be first */ 00031 00032 #include <lib/tl/refnode.h> 00033 #include <lib/tl/linkedlist.h> 00034 #include <lib/tl/tlstring.h> 00035 00036 // As defined further down: 00037 class _InternalSourceFileNode; 00038 00040 typedef RefNode<_InternalSourceFileNode> SourceFileNode; 00041 00042 // As defined in sparchive.h. 00043 class SourcePositionArchive; 00044 00045 // As defined in spcache.h 00046 class SourcePositionCache; 00047 00048 00066 class _InternalSourceFileNode : 00067 InternalRefNodeBase_ThreadSave, 00068 LinkedListBase<_InternalSourceFileNode> 00069 { 00070 friend class SourcePositionArchive; 00071 friend class LinkedList<_InternalSourceFileNode>; 00072 friend class RefNode<_InternalSourceFileNode>; 00073 friend bool operator==(const SourceFileNode &a,const SourceFileNode &b); 00074 public: 00080 static SourceFileNode CreateSingleNode(const TLString &path); 00081 private: 00082 TLString _path; 00083 00086 SourcePositionArchive *pos_archive; 00087 00089 _InternalSourceFileNode *up; 00091 LinkedList<_InternalSourceFileNode> down; 00092 00094 int parent_include_line; 00095 int parent_include_lpos; 00096 00098 filepos_t include_stmt_pos; 00099 size_t include_stmt_len; 00100 00106 SourcePositionCache *pos_cache; 00107 00109 void _DestroyPosCache(); 00110 00118 inline void _DetachArchive() 00119 { if(this) { pos_archive=NULL; _DestroyPosCache(); } } 00120 00124 inline void _AddChild(_InternalSourceFileNode *isf) 00125 { down.append(isf); _InternalRefNodeBase_aqref(); } 00126 inline void _DelChild(_InternalSourceFileNode *isf) 00127 { down.dequeue(isf); _InternalRefNodeBase_deref(); } 00128 00130 inline bool test_equal(const _InternalSourceFileNode &b) const 00131 { return(this==&b); } 00132 00134 _InternalSourceFileNode(const _InternalSourceFileNode &); 00135 void operator=(const _InternalSourceFileNode &); 00136 00140 _InternalSourceFileNode(const TLString &path, 00141 _InternalSourceFileNode *parent, 00142 SourcePositionArchive *pos_archive); 00143 public: 00147 ~_InternalSourceFileNode(); 00148 00150 inline SourcePositionArchive *archive() const 00151 { return(this ? pos_archive : NULL); } 00152 00154 inline TLString path() const 00155 { return(this ? _path : TLString()); } 00156 00163 TLString IncludeHierarchyStr() const; 00164 }; 00165 00173 inline bool operator==(const SourceFileNode &a,const SourceFileNode &b) 00174 { return((a && b) ? a->test_equal(*b) : (!a && !b)); } 00175 00181 inline bool operator!=(const SourceFileNode &a,const SourceFileNode &b) 00182 { return(!operator==(a,b)); } 00183 00184 00185 #endif /* _LIB_SOURCEPOS_SOURCEFILE_H_ */