1*0Sstevel@tonic-gate // Copyright (c) 1994 James Clark
2*0Sstevel@tonic-gate // See the file COPYING for copying permission.
3*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
4*0Sstevel@tonic-gate
5*0Sstevel@tonic-gate #ifndef Location_INCLUDED
6*0Sstevel@tonic-gate #define Location_INCLUDED 1
7*0Sstevel@tonic-gate #ifdef __GNUG__
8*0Sstevel@tonic-gate #pragma interface
9*0Sstevel@tonic-gate #endif
10*0Sstevel@tonic-gate
11*0Sstevel@tonic-gate #include "types.h"
12*0Sstevel@tonic-gate #include "Boolean.h"
13*0Sstevel@tonic-gate #include "Ptr.h"
14*0Sstevel@tonic-gate #include "Resource.h"
15*0Sstevel@tonic-gate #include "Boolean.h"
16*0Sstevel@tonic-gate #include "Vector.h"
17*0Sstevel@tonic-gate #include "Owner.h"
18*0Sstevel@tonic-gate #include "StringC.h"
19*0Sstevel@tonic-gate #include "rtti.h"
20*0Sstevel@tonic-gate
21*0Sstevel@tonic-gate #ifdef SP_NAMESPACE
22*0Sstevel@tonic-gate namespace SP_NAMESPACE {
23*0Sstevel@tonic-gate #endif
24*0Sstevel@tonic-gate
25*0Sstevel@tonic-gate class ExternalInfo;
26*0Sstevel@tonic-gate class EntityOrigin;
27*0Sstevel@tonic-gate class InputSourceOrigin;
28*0Sstevel@tonic-gate class Entity;
29*0Sstevel@tonic-gate class EntityDecl;
30*0Sstevel@tonic-gate class Location;
31*0Sstevel@tonic-gate class Markup;
32*0Sstevel@tonic-gate class Text;
33*0Sstevel@tonic-gate class NamedCharRef;
34*0Sstevel@tonic-gate
35*0Sstevel@tonic-gate class SP_API Origin : public Resource {
36*0Sstevel@tonic-gate public:
37*0Sstevel@tonic-gate virtual ~Origin();
38*0Sstevel@tonic-gate virtual const EntityOrigin *asEntityOrigin() const;
39*0Sstevel@tonic-gate virtual const InputSourceOrigin *asInputSourceOrigin() const;
40*0Sstevel@tonic-gate virtual const Location &parent() const = 0;
41*0Sstevel@tonic-gate virtual Index refLength() const;
42*0Sstevel@tonic-gate virtual Boolean origChars(const Char *&) const;
43*0Sstevel@tonic-gate virtual Boolean inBracketedTextOpenDelim() const;
44*0Sstevel@tonic-gate virtual Boolean inBracketedTextCloseDelim() const;
45*0Sstevel@tonic-gate virtual Boolean isNumericCharRef(const Markup *&markup) const;
46*0Sstevel@tonic-gate virtual Boolean isNamedCharRef(Index ind, NamedCharRef &ref) const;
47*0Sstevel@tonic-gate virtual const EntityDecl *entityDecl() const;
48*0Sstevel@tonic-gate virtual Boolean defLocation(Offset off, const Origin *&, Index &) const;
49*0Sstevel@tonic-gate virtual const Markup *markup() const;
50*0Sstevel@tonic-gate virtual const Entity *entity() const;
51*0Sstevel@tonic-gate virtual const ExternalInfo *externalInfo() const;
52*0Sstevel@tonic-gate virtual Offset startOffset(Index ind) const;
53*0Sstevel@tonic-gate const StringC *entityName() const;
54*0Sstevel@tonic-gate };
55*0Sstevel@tonic-gate
56*0Sstevel@tonic-gate class SP_API ProxyOrigin : public Origin {
57*0Sstevel@tonic-gate public:
58*0Sstevel@tonic-gate ProxyOrigin(const Origin *origin);
59*0Sstevel@tonic-gate const EntityOrigin *asEntityOrigin() const;
60*0Sstevel@tonic-gate const InputSourceOrigin *asInputSourceOrigin() const;
61*0Sstevel@tonic-gate const Location &parent() const;
62*0Sstevel@tonic-gate Index refLength() const;
63*0Sstevel@tonic-gate Boolean origChars(const Char *&) const;
64*0Sstevel@tonic-gate Boolean inBracketedTextOpenDelim() const;
65*0Sstevel@tonic-gate Boolean inBracketedTextCloseDelim() const;
66*0Sstevel@tonic-gate Boolean isNumericCharRef(const Markup *&markup) const;
67*0Sstevel@tonic-gate Boolean isNamedCharRef(Index ind, NamedCharRef &ref) const;
68*0Sstevel@tonic-gate const EntityDecl *entityDecl() const;
69*0Sstevel@tonic-gate Boolean defLocation(Offset off, const Origin *&, Index &) const;
70*0Sstevel@tonic-gate const Markup *markup() const;
71*0Sstevel@tonic-gate const Entity *entity() const;
72*0Sstevel@tonic-gate const ExternalInfo *externalInfo() const;
73*0Sstevel@tonic-gate Offset startOffset(Index ind) const;
74*0Sstevel@tonic-gate private:
75*0Sstevel@tonic-gate const Origin *origin_;
76*0Sstevel@tonic-gate };
77*0Sstevel@tonic-gate
78*0Sstevel@tonic-gate class SP_API Location {
79*0Sstevel@tonic-gate public:
80*0Sstevel@tonic-gate Location();
81*0Sstevel@tonic-gate Location(Origin *, Index);
82*0Sstevel@tonic-gate Location(ConstPtr<Origin>, Index);
83*0Sstevel@tonic-gate void operator+=(Index i) { index_ += i; }
84*0Sstevel@tonic-gate void operator-=(Index i) { index_ -= i; }
index()85*0Sstevel@tonic-gate Index index() const { return index_; }
origin()86*0Sstevel@tonic-gate const ConstPtr<Origin> &origin() const { return origin_; }
clear()87*0Sstevel@tonic-gate void clear() { origin_.clear(); }
swap(Location & to)88*0Sstevel@tonic-gate void swap(Location &to) {
89*0Sstevel@tonic-gate origin_.swap(to.origin_);
90*0Sstevel@tonic-gate Index tem = to.index_;
91*0Sstevel@tonic-gate to.index_ = index_;
92*0Sstevel@tonic-gate index_ = tem;
93*0Sstevel@tonic-gate }
94*0Sstevel@tonic-gate private:
95*0Sstevel@tonic-gate ConstPtr<Origin> origin_;
96*0Sstevel@tonic-gate Index index_;
97*0Sstevel@tonic-gate };
98*0Sstevel@tonic-gate
99*0Sstevel@tonic-gate class SP_API ExternalInfo {
100*0Sstevel@tonic-gate RTTI_CLASS
101*0Sstevel@tonic-gate public:
102*0Sstevel@tonic-gate virtual ~ExternalInfo();
103*0Sstevel@tonic-gate };
104*0Sstevel@tonic-gate
105*0Sstevel@tonic-gate class SP_API NamedCharRef {
106*0Sstevel@tonic-gate public:
107*0Sstevel@tonic-gate enum RefEndType {
108*0Sstevel@tonic-gate endOmitted,
109*0Sstevel@tonic-gate endRE,
110*0Sstevel@tonic-gate endRefc
111*0Sstevel@tonic-gate };
112*0Sstevel@tonic-gate NamedCharRef();
113*0Sstevel@tonic-gate NamedCharRef(Index, RefEndType, const StringC &);
114*0Sstevel@tonic-gate Index refStartIndex() const;
115*0Sstevel@tonic-gate RefEndType refEndType() const;
116*0Sstevel@tonic-gate const StringC &origName() const;
117*0Sstevel@tonic-gate void set(Index, RefEndType, const Char *, size_t);
118*0Sstevel@tonic-gate private:
119*0Sstevel@tonic-gate Index refStartIndex_;
120*0Sstevel@tonic-gate RefEndType refEndType_;
121*0Sstevel@tonic-gate StringC origName_;
122*0Sstevel@tonic-gate };
123*0Sstevel@tonic-gate
124*0Sstevel@tonic-gate struct SP_API InputSourceOriginNamedCharRef {
125*0Sstevel@tonic-gate Index replacementIndex;
126*0Sstevel@tonic-gate size_t origNameOffset;
127*0Sstevel@tonic-gate Index refStartIndex;
128*0Sstevel@tonic-gate NamedCharRef::RefEndType refEndType;
129*0Sstevel@tonic-gate };
130*0Sstevel@tonic-gate
131*0Sstevel@tonic-gate class SP_API InputSourceOrigin : public Origin {
132*0Sstevel@tonic-gate public:
133*0Sstevel@tonic-gate virtual void noteCharRef(Index replacementIndex, const NamedCharRef &) = 0;
134*0Sstevel@tonic-gate virtual void setExternalInfo(ExternalInfo *) = 0;
135*0Sstevel@tonic-gate virtual InputSourceOrigin *copy() const = 0;
136*0Sstevel@tonic-gate static InputSourceOrigin *make();
137*0Sstevel@tonic-gate static InputSourceOrigin *make(const Location &refLocation);
138*0Sstevel@tonic-gate };
139*0Sstevel@tonic-gate
140*0Sstevel@tonic-gate // a delimiter specified in bracketed text
141*0Sstevel@tonic-gate
142*0Sstevel@tonic-gate class SP_API BracketOrigin : public Origin {
143*0Sstevel@tonic-gate public:
144*0Sstevel@tonic-gate enum Position { open, close };
145*0Sstevel@tonic-gate BracketOrigin(const Location &, Position);
146*0Sstevel@tonic-gate const Location &parent() const;
147*0Sstevel@tonic-gate Boolean inBracketedTextOpenDelim() const;
148*0Sstevel@tonic-gate Boolean inBracketedTextCloseDelim() const;
149*0Sstevel@tonic-gate private:
150*0Sstevel@tonic-gate Position pos_;
151*0Sstevel@tonic-gate Location loc_;
152*0Sstevel@tonic-gate };
153*0Sstevel@tonic-gate
154*0Sstevel@tonic-gate class SP_API ReplacementOrigin : public Origin {
155*0Sstevel@tonic-gate public:
156*0Sstevel@tonic-gate ReplacementOrigin(const Location &, Char origChar);
157*0Sstevel@tonic-gate const Location &parent() const;
158*0Sstevel@tonic-gate Boolean origChars(const Char *&) const;
159*0Sstevel@tonic-gate private:
160*0Sstevel@tonic-gate Location loc_;
161*0Sstevel@tonic-gate Char origChar_;
162*0Sstevel@tonic-gate };
163*0Sstevel@tonic-gate
164*0Sstevel@tonic-gate class SP_API MultiReplacementOrigin : public Origin {
165*0Sstevel@tonic-gate public:
166*0Sstevel@tonic-gate MultiReplacementOrigin(const Location &, StringC &origChars);
167*0Sstevel@tonic-gate const Location &parent() const;
168*0Sstevel@tonic-gate Boolean origChars(const Char *&) const;
169*0Sstevel@tonic-gate private:
170*0Sstevel@tonic-gate Location loc_;
171*0Sstevel@tonic-gate StringC origChars_;
172*0Sstevel@tonic-gate };
173*0Sstevel@tonic-gate
174*0Sstevel@tonic-gate inline
refStartIndex()175*0Sstevel@tonic-gate Index NamedCharRef::refStartIndex() const
176*0Sstevel@tonic-gate {
177*0Sstevel@tonic-gate return refStartIndex_;
178*0Sstevel@tonic-gate }
179*0Sstevel@tonic-gate
180*0Sstevel@tonic-gate inline
refEndType()181*0Sstevel@tonic-gate NamedCharRef::RefEndType NamedCharRef::refEndType() const
182*0Sstevel@tonic-gate {
183*0Sstevel@tonic-gate return refEndType_;
184*0Sstevel@tonic-gate }
185*0Sstevel@tonic-gate
186*0Sstevel@tonic-gate inline
origName()187*0Sstevel@tonic-gate const StringC &NamedCharRef::origName() const
188*0Sstevel@tonic-gate {
189*0Sstevel@tonic-gate return origName_;
190*0Sstevel@tonic-gate }
191*0Sstevel@tonic-gate
192*0Sstevel@tonic-gate #ifdef SP_NAMESPACE
193*0Sstevel@tonic-gate }
194*0Sstevel@tonic-gate #endif
195*0Sstevel@tonic-gate
196*0Sstevel@tonic-gate #endif /* not Location_INCLUDED */
197