SourceLocation.hpp
Go to the documentation of this file.
1 /*----------------------------------------------------------------------------*/
2 /* */
3 /* Copyright (c) 1995, 2004 IBM Corporation. All rights reserved. */
4 /* Copyright (c) 2005-2009 Rexx Language Association. All rights reserved. */
5 /* */
6 /* This program and the accompanying materials are made available under */
7 /* the terms of the Common Public License v1.0 which accompanies this */
8 /* distribution. A copy is also available at the following address: */
9 /* http://www.oorexx.org/license.html */
10 /* */
11 /* Redistribution and use in source and binary forms, with or */
12 /* without modification, are permitted provided that the following */
13 /* conditions are met: */
14 /* */
15 /* Redistributions of source code must retain the above copyright */
16 /* notice, this list of conditions and the following disclaimer. */
17 /* Redistributions in binary form must reproduce the above copyright */
18 /* notice, this list of conditions and the following disclaimer in */
19 /* the documentation and/or other materials provided with the distribution. */
20 /* */
21 /* Neither the name of Rexx Language Association nor the names */
22 /* of its contributors may be used to endorse or promote products */
23 /* derived from this software without specific prior written permission. */
24 /* */
25 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
26 /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
27 /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS */
28 /* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
29 /* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
30 /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
31 /* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */
32 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY */
33 /* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
34 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
35 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
36 /* */
37 /*----------------------------------------------------------------------------*/
38 /******************************************************************************/
39 /* REXX Kernel SourceLocation.hpp */
40 /* */
41 /* Primitive Translator Token Class Definitions */
42 /* */
43 /******************************************************************************/
44 #ifndef Included_SourceLocation
45 #define Included_SourceLocation
46 
47 
48 class SourceLocation /* token/clause location information */
49 {
50 public:
51  inline SourceLocation() : /*startLine(0), startOffset(0), endLine(0), endOffset(0),*/ limitedTrace(false) {};
52  inline size_t getLineNumber() const { return startLine; }
53  inline sizeB_t getOffset() const { return startOffset; }
54  inline size_t getEndLine() const { return endLine; }
55  inline sizeB_t getEndOffset() const { return endOffset; }
56  inline bool isLimitedTrace() const { return limitedTrace; }
57 
58  inline void setLineNumber(size_t l) { startLine = l; }
59  inline void setOffset(sizeB_t l) { startOffset = l; }
60  inline void setEndLine(size_t l) { endLine = l; }
61  inline void setEndOffset(sizeB_t l) { endOffset = l; }
62  inline void setLimitedTrace(bool b) { limitedTrace = b; }
63 
64  inline void setStart(SourceLocation &l)
65  {
67  startOffset = l.getOffset();
68  }
69 
70  inline void setEnd(SourceLocation &l)
71  {
72  setEnd(l.getEndLine(), l.getEndOffset());
73  }
74 
75  inline void setStart(size_t line, sizeB_t offset)
76  {
77  startLine = line;
78  startOffset = offset;
79  }
80 
81  inline void setEnd(size_t line, sizeB_t offset)
82  {
83  // only set if this makes sense
84  if (line > startLine || (line == startLine && offset > startOffset))
85  {
86  endLine = line;
87  endOffset = offset;
88  }
89 
90  }
91 
92  inline void setLocation(size_t line, sizeB_t offset, size_t end, sizeB_t end_offset, bool limited_trace=false)
93  {
94  startLine = line;
95  startOffset = offset;
96  endLine = end;
97  endOffset = end_offset;
98  limitedTrace = limited_trace;
99  }
100 
101  inline void setLocation(SourceLocation &l)
102  {
103  startLine = l.startLine;
105  endLine = l.endLine;
106  endOffset = l.endOffset;
108  }
109 
110  inline const SourceLocation & operator= (const SourceLocation &l)
111  {
112  startLine = l.startLine;
114  endLine = l.endLine;
115  endOffset = l.endOffset;
117  return *this;
118  }
119 
120 protected:
121  size_t startLine; // file line start location
122  sizeB_t startOffset; // offset within the file line
123  size_t endLine; // file line end location
124  sizeB_t endOffset; // file end offset
125  bool limitedTrace; // Used by /*...*/ and {...} to limit the traceBack when error "unmatched"
126 };
127 
128 
129 #endif
sizeB_t getOffset() const
size_t getEndLine() const
void setOffset(sizeB_t l)
size_t getLineNumber() const
void setEnd(SourceLocation &l)
void setStart(SourceLocation &l)
void setEndOffset(sizeB_t l)
void setEndLine(size_t l)
void setLocation(SourceLocation &l)
void setStart(size_t line, sizeB_t offset)
void setLocation(size_t line, sizeB_t offset, size_t end, sizeB_t end_offset, bool limited_trace=false)
sizeB_t getEndOffset() const
void setLineNumber(size_t l)
bool isLimitedTrace() const
void setLimitedTrace(bool b)
const SourceLocation & operator=(const SourceLocation &l)
void setEnd(size_t line, sizeB_t offset)
stringsizeB_t sizeB_t
Definition: rexx.h:248
char line[LINEBUFSIZE]