00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "sourcepos.h"
00019 #include "sparchive.h"
00020
00021
00022 TLString _InternalSourcePosition::IncludeHierarchyStr() const
00023 {
00024 if(!this || !_file) return TLString();
00025
00026 return(_file->IncludeHierarchyStr());
00027 }
00028
00029
00030 TLString _InternalSourcePosition::PosString(bool with_file) const
00031 {
00032 if(!this)
00033 {
00034 return("(null)");
00035 }
00036 else if(_line<0)
00037 {
00038 if(with_file) return(path());
00039 else return("");
00040 }
00041 else if(_lpos<0)
00042 {
00043 TLString dest;
00044 if(with_file) dest.sprintf("%s:%d",path().str(),_line);
00045 else dest.sprintf("%d",_line);
00046 return(dest);
00047 }
00048 else
00049 {
00050 TLString dest;
00051 if(with_file) dest.sprintf("%s:%d:%d",path().str(),_line,_lpos);
00052 else dest.sprintf("%d:%d",_line,_lpos);
00053 return(dest);
00054 }
00055 return TLString();
00056 }
00057
00058
00059 TLString _InternalSourcePosition::PosRangeString(const SourcePosition &end,
00060 bool with_file) const
00061 {
00062 TLString dest;
00063
00064 if(!this) return(dest);
00065
00066 int line0=_line;
00067 int lpos0=_lpos;
00068 SourceFileNode sfn0=file();
00069
00070 int line1=end->_line;
00071 int lpos1=end->_lpos;
00072 SourceFileNode sfn1=end->file();
00073
00075 if(sfn0!=sfn1)
00076 {
00077 dest=PosString(with_file)+".."+end->PosString(with_file);
00078 }
00079 else if(line0!=line1 || lpos0<0 || lpos1<0)
00080 {
00081 do_it_above:;
00082
00083 dest=PosString(with_file)+"..";
00084
00085
00086 TLString tmp;
00087 if(line1<0)
00088 { tmp="??"; }
00089 else if(lpos1<0)
00090 { tmp.sprintf("%d",line1); }
00091 else
00092 { tmp.sprintf("%d:%d",line1,lpos1); }
00093 dest+=tmp;
00094 }
00095 else if(lpos0!=lpos1)
00096 {
00097 if(line0<0 || line1<0)
00098 { goto do_it_above; }
00099
00100 if(with_file)
00101 { dest.sprintf("%s:%d:[%d..%d]",
00102 sfn0->path().str(),line0,lpos0,lpos1); }
00103 else
00104 { dest.sprintf("%d:[%d..%d]",line0,lpos0,lpos1); }
00105 }
00106 else
00107 {
00108
00109 dest=PosString(with_file);
00110 }
00111
00112 return(dest);
00113 }
00114
00115
00116 TLString _InternalSourcePosition::PosStringRelative(
00117 const SourcePosition &rpos) const
00118 {
00119 if(!this || _file!=rpos->_file)
00120 { return(PosString()); }
00121
00122 TLString dest;
00123 if(_lpos<0)
00124 { dest.sprintf("%d",_line); }
00125 else
00126 { dest.sprintf("%d:%d",_line,_lpos); }
00127
00128 return(dest);
00129 }
00130
00131
00132 bool _InternalSourcePosition::test_equal(const _InternalSourcePosition &sp)
00133 const
00134 {
00135 if(!this || !&sp) return(0);
00136
00137
00138 if(this==&sp) return(1);
00139
00140
00141 if(_line!=sp._line || _lpos!=sp._lpos || _file!=sp._file) return(0);
00142
00143 return(1);
00144 }
00145
00146
00147 SourcePosition _InternalSourcePosition::CreateSinglePosition(
00148 const SourceFileNode &sfn,int line,int lpos)
00149 {
00150 _InternalSourcePosition *isp=new _InternalSourcePosition(sfn,line,lpos);
00151 return(SourcePosition(isp));
00152 }
00153
00154
00155 _InternalSourcePosition::_InternalSourcePosition(const SourceFileNode &_fnode,
00156 int xline,int xlpos) :
00157 InternalRefNodeBase_ThreadSave(),
00158 _file(_fnode)
00159 {
00160 _line=xline;
00161 _lpos=xlpos;
00162 }
00163
00164 _InternalSourcePosition::~_InternalSourcePosition()
00165 {
00166
00167
00168 if(_file && _file->archive())
00169 {
00170
00171
00172 _file->archive()->DestroyingISP(this);
00173 }
00174 }