Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

/ray/src/lib/sourcepos/sourcefile.cc

Go to the documentation of this file.
00001 /*
00002  * lib/sourcepos/sourcfile.cc
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 #include "sourcefile.h"
00019 #include "spcache.h"
00020 #include "sparchive.h"
00021 
00022 
00023 TLString _InternalSourceFileNode::IncludeHierarchyStr() const
00024 {
00025     if(!this)  return TLString();
00026     
00027     // This is not a hierarchy but the current file, if up=NULL. 
00028     if(!up)  return TLString();
00029     
00030     TLString str;
00031     str+="In file \""+_path+"\" [is the following correct?? FIMXE?]";
00032     
00033     for(const _InternalSourceFileNode *i=this; i->up; i=i->up)
00034     {
00035         str+=",\n\tincluded from "+i->up->_path;
00036         TLString loc;
00037         if(i->parent_include_line>=0 && i->parent_include_lpos>=0)
00038         { loc.sprintf(":%d:%d",i->parent_include_line,i->parent_include_lpos); }
00039         else if(i->parent_include_line>=0)
00040         { loc.sprintf(":%d",i->parent_include_line); }
00041         else if(i->parent_include_lpos>=0)
00042         { loc.sprintf(":???:%d",i->parent_include_lpos); }
00043         str+=loc;
00044     }
00045     
00046     str+=":\n";
00047     
00048     return(str);
00049 }
00050 
00051 
00052 SourceFileNode _InternalSourceFileNode::CreateSingleNode(const TLString &path)
00053 {
00054     _InternalSourceFileNode *ifn=new _InternalSourceFileNode(path,NULL,NULL);
00055     return(SourceFileNode(ifn));
00056 }
00057 
00058 
00059 void _InternalSourceFileNode::_DestroyPosCache()
00060 {
00061     if(!this) return;
00062     
00063     // Leave that outside class def or we may get trouble with 
00064     // "invalid use of undefined type `struct SourcePositionCache'". 
00065     DELETE(pos_cache);
00066 }
00067 
00068 
00069 _InternalSourceFileNode::_InternalSourceFileNode(const TLString &xpath,
00070     _InternalSourceFileNode *parent,SourcePositionArchive *_pos_archive) : 
00071     InternalRefNodeBase_ThreadSave(),
00072     LinkedListBase<_InternalSourceFileNode>(),
00073     _path(xpath),
00074     down()
00075 {
00076     up=parent;
00077     
00078     pos_archive=_pos_archive;
00079     
00080     parent_include_line=-1;
00081     parent_include_lpos=-1;
00082     include_stmt_pos=-1;
00083     include_stmt_len=0;  // (unsigned)
00084     
00085     if(pos_archive)
00086     {  pos_cache=new SourcePositionCache();  }
00087     else
00088     {  pos_cache=NULL;  }
00089     
00090     if(up)
00091     {  up->_AddChild(this);  }
00092 }
00093 
00094 _InternalSourceFileNode::~_InternalSourceFileNode()
00095 {
00096     // We may not have refcnt=0 and hence get destroyed if there are 
00097     // still some children left. 
00098     CritAssert(down.IsEmpty());
00099     
00100     // Make sure we delete our down pointer at the parent: 
00101     if(up)
00102     {
00103         up->_DelChild(this);
00104         up=NULL;
00105     }
00106     
00107     // Destroy position cache if still there: 
00108     DELETE(pos_cache);
00109     
00110     // Inform the pos archive: 
00111     if(pos_archive)
00112     {  pos_archive->DestroyingISF(this);  }
00113 }

Generated on Sat Feb 19 22:33:46 2005 for Ray by doxygen 1.3.5