00001 /* 00002 * lib/lex/location.cc 00003 * 00004 * Source code location (file/line) representation. 00005 * 00006 * Copyright (c) 2003--2004 by Wolfgang Wieser ] wwieser (a) gmx <*> de [ 00007 * 00008 * This file may be distributed and/or modified under the terms of the 00009 * GNU General Public License version 2 as published by the Free Software 00010 * Foundation. (See COPYING.GPL for details.) 00011 * 00012 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00013 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00014 * 00015 */ 00016 00017 #include "location.h" 00018 00019 00020 TLString SCLocationRange::RangeString(int with_files) const 00021 { 00022 TLString str; 00023 if(with_files>1) 00024 { str+=loc0.pos->IncludeHierarchyStr(); } 00025 str+=loc0.pos->PosRangeString(loc1.pos,with_files); 00026 return(str); 00027 } 00028 00029 00030 TLString SCLocationRange::RelString(const SCLocationRange &rloc) const 00031 { 00032 if(loc0.pos->file()==loc1.pos->file() && 00033 loc0.pos->file()==rloc.loc0.pos->file() && 00034 loc0.pos->file()==rloc.loc1.pos->file() ) 00035 { 00036 return(RangeString(/*with_file=*/0)); 00037 } 00038 else 00039 { return(RangeString()); } 00040 } 00041 00042 00043 TLString SCLocationRange::RelString(const SCLocation &rloc) const 00044 { 00045 if(loc0.pos->file()==loc1.pos->file() && 00046 loc0.pos->file()==rloc.pos->file() ) 00047 { 00048 return(RangeString(/*with_file=*/0)); 00049 } 00050 else 00051 { return(RangeString()); } 00052 } 00053 00054 00055 TLString SCLocation::LocString(int with_inc_hierarchy) const 00056 { 00057 TLString str; 00058 if(with_inc_hierarchy) 00059 { str+=pos->IncludeHierarchyStr(); } 00060 str+=pos->PosString(); 00061 return(str); 00062 } 00063 00064 00065 TLString SCLocation::RelString(const SCLocation &rloc) const 00066 { 00067 return(pos->PosStringRelative(rloc.pos)); 00068 } 00069 00070 00071 SCLocation::SCLocation(const TLString &path,int line,int lpos) : 00072 pos() 00073 { 00074 if(!path && line<0 && lpos<0) return; 00075 00076 SourceFileNode sfn; 00077 if(path) 00078 { sfn=_InternalSourceFileNode::CreateSingleNode(path); } 00079 00080 pos=_InternalSourcePosition::CreateSinglePosition(sfn,line,pos); 00081 }