File: Ptree.h

package info (click to toggle)
openc%2B%2B 2.8-4
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 5,464 kB
  • ctags: 3,333
  • sloc: cpp: 19,071; sh: 12,793; ansic: 3,549; makefile: 577
file content (413 lines) | stat: -rw-r--r-- 12,816 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
#ifndef guard_opencxx_Ptree_h
#define guard_opencxx_Ptree_h

//@beginlicenses@
//@license{chiba_tokyo}{}@
//@license{contributors}{}@
//
//  Permission to use, copy, distribute and modify this software and its  
//  documentation for any purpose is hereby granted without fee, provided that
//  the above copyright notice appears in all copies and that both that copyright
//  notice and this permission notice appear in supporting documentation.
// 
//  1997-2001 Shigeru Chiba, Tokyo Institute of Technology. make(s) no representations about the suitability of this
//  software for any purpose. It is provided "as is" without express or implied
//  warranty.
//  
//  Copyright (C)  1997-2001 Shigeru Chiba, Tokyo Institute of Technology.
//
//  -----------------------------------------------------------------
//
//  Permission to use, copy, distribute and modify this software and its  
//  documentation for any purpose is hereby granted without fee, provided that
//  the above copyright notice appears in all copies and that both that copyright
//  notice and this permission notice appear in supporting documentation.
// 
//  Other Contributors (see file AUTHORS) make(s) no representations about the suitability of this
//  software for any purpose. It is provided "as is" without express or implied
//  warranty.
//  
//  Copyright (C)  Other Contributors (see file AUTHORS)
//
//@endlicenses@

#include <iosfwd>
#include <opencxx/parser/GC.h>
#include <opencxx/parser/deprecated.h>
#include <opencxx/parser/PtreeUtil.h>

namespace Opencxx
{

class AbstractTranslatingWalker;
class AbstractTypingWalker;
class TypeInfo;

#ifdef __opencxx
metaclass QuoteClass Ptree;           // get qMake() available
#endif

class Ptree : public LightObject {
public:

    /** This returns true if the metaobject indicates a lexical token. */
    virtual bool IsLeaf() const = 0;

    /** Prints the metaobject on the </code>os</code> for debugging. Sublists are surrounded by [ and ]. */
    void Display(std::ostream&);
    void Display();


OPENCXX_DEPRECATED_PUBLIC:

    /** @deprecaed Use PtreeUtil */
    bool Eq(char x);

    /** @deprecaed Use PtreeUtil */
    bool Eq(const char*);

    /** @deprecaed Use PtreeUtil */
    bool Eq(const char*, int);

    /** @deprecaed Use PtreeUtil */
    bool Eq(Ptree* p) { return Eq(this, p); }

    /** @deprecated Use Display() */
    void Display2(std::ostream& os);

public:

    /** @todo document */
    virtual void Print(std::ostream&, int, int) = 0;

    /** @todo document */
    int Write(std::ostream&);

    /** Writes the metaobject to the file specified by out. Unlike Display() , sublists are not surrounded by [ and ]. This member function returns the number of written lines. */
    virtual int Write(std::ostream&, int) = 0;

    /** @todo document */
    void PrintIndent(std::ostream&, int);


    /** Converts the parse tree into a character string and returns it. */
    char* ToString();

    /** @todo document */
    virtual void PrintOn(std::ostream&) const = 0;

    /** Returns position in the char buffer when the
        text parsed as <code>this</code> starts.
         */
    char* GetPosition() { return data.leaf.position; }

    /** Returns the length of the text parsed as <code>this</code>. */
    int GetLength() { return data.leaf.length; }


    /**  */
          Ptree* Car()       { return data.nonleaf.child; }

    /**  */
    const Ptree* Car() const { return data.nonleaf.child; }

    /**  */
          Ptree* Cdr()       { return data.nonleaf.next; }

    /**  */
    const Ptree* Cdr() const { return data.nonleaf.next; }

OPENCXX_DEPRECATED_PUBLIC:

    /** @deprecated Use <code>Cdr()->Car()</code>.
    */
    Ptree* Cadr() 
    { 
        Deprecated("Ptree::Cadr()", "p->Cdr()->Car()");
        return Cdr()->Car(); 
    }

    /** @deprecated Rationale: bloats interface 
        (use <code>Cdr()->Cdr()</code>).
    */
    Ptree* Cddr() 
    { 
        Deprecated("Ptree::Cadr()", "p->Cdr()->Cdr()");
        return Cdr()->Cdr(); 
    }

    /** @deprecated Use PtreeUtil */
    Ptree* Ca_ar();

public:

    /**  */
    void SetCar(Ptree* p) { data.nonleaf.child = p; }

    /**  */
    void SetCdr(Ptree* p) { data.nonleaf.next = p; }


OPENCXX_DEPRECATED_PUBLIC:

    /** Returns position in text buffer corresponding to
        left-most character parsed as <code>this</code>.
        
        @todo Is this equivalent to GetPosition()? */
    char* LeftMost();

    /** Returns position in text buffer corresponding to
        left-most character parsed as <code>this</code>.
     */
    char* RightMost();

public:
    /**  */
    bool IsA(int);

    /** Returns identifier of a node. 
        @see token-names.h */
    virtual int What();

    /** Returns encoded type for nodes that support it. */
    virtual char* GetEncodedType();

    /** Returns encoded name for nodes that support it. */
    virtual char* GetEncodedName();

    /** Calls appropriate Translate... method in <code>walker</code>,
        depending on dynamic type of <code>this</code>.
        
        @note This is <i>Visit</i> function of <i>Visitor Pattern</i>.
      */
    virtual Ptree* Translate(AbstractTranslatingWalker* walker);

    /** Calls appropriate Typeof... method in <code>walker</code>
        passing <code>ti</code> to it.
        
        @note This is <i>Visit</i> function of <i>Visitor Pattern</i>.
      */
    virtual void Typeof(AbstractTypingWalker* walker, TypeInfo& ti);

OPENCXX_DEPRECATED_PUBLIC:

    /**  @deprecated Use IsA(int) and ||. */
    bool IsA(int, int);

    /**  @deprecated Use IsA(int) and ||. */
    bool IsA(int, int, int);

    /** @deprecated Use PtreeUtil */
    Ptree* Last() { return Last(this); }
    
    /** @deprecated Use PtreeUtil */
    Ptree* First() { return First(this); }

    /** @deprecated Use PtreeUtil */
    Ptree* Rest() { return Rest(this); }

    /** @deprecated Use PtreeUtil */
    Ptree* Second() { return Second(this); }

    /** @deprecated Use PtreeUtil */
    Ptree* Third() { return Third(this); }

    /** @deprecated Use PtreeUtil */
    Ptree* Nth(int n) { return Nth(this, n); }

    /** @deprecated Use PtreeUtil */
    int Length() { return Length(this); }

    /** @deprecated Use PtreeUtil */
    Ptree* ListTail(int n) { return ListTail(this, n); }

    /** Returns true if lst and x are equal. @deprecated Use PtreeUtil */
    static bool Eq(Ptree* lst, char x);

    /** Returns true if lst and x are equal. @deprecated Use PtreeUtil */
    static bool Eq(Ptree* lst, const char* x);

    /** @todo document @deprecated Use PtreeUtil */
    static bool Eq(Ptree* lst, const char* x, int);

    /** Returns true if lst and x are equal. Determines the equivalence by comparing the pointers. @deprecated Use PtreeUtil */
    static bool Eq(Ptree*, Ptree*);

    /** @deprecated Use PtreeUtil  */
    static bool Equiv(Ptree*, Ptree*);

    /** Recursively compares x and y and returns true if they are equivalent. @deprecated Use PtreeUtil */
    static bool Equal(Ptree*, Ptree*);
    
    /** Returns the last cons cell, which is a 
        list containing only the last element of <code>lst</code>. 
        @deprecated Use PtreeUtil 
      */
    static Ptree* Last(Ptree*);

    /** Returns the first element of <code>lst</code>. @deprecated Use PtreeUtil */
    static Ptree* First(Ptree*);
    
    /** Returns the rest of <code>lst</code> except the first element, 
        that is, the <i>cdr</i> field of <code>lst</code>. 
        @deprecated Use PtreeUtil */
    static Ptree* Rest(Ptree*);
    
    /** Returns the second element of <code>lst</code>. 
        @deprecated Use PtreeUtil */
    static Ptree* Second(Ptree*);

    /** Returns the third element of <code>lst</code>. @deprecated Use PtreeUtil */
    static Ptree* Third(Ptree*);

    /** Returns the n-th element of lst. 
        <code>Nth(lst, 0)</code> is equivalent to <code>First(lst)</code>. 
        @deprecated Use PtreeUtil */
    static Ptree* Nth(Ptree*, int);
    
    /** Returns the number of the elements of <code>lst</code>. If lst 
        is not a list, then this returns a negative number. 
        @deprecated Use PtreeUtil */
    static int Length(Ptree*); 
    
    /** Returns a sublist of lst obtained by omitting the first <code>k</code>
        elements. <code>ListTail(lst, 1)</code> is equivalent 
        to <code>Rest(lst)</code>. @deprecated Use PtreeUtil */
    static Ptree* ListTail(Ptree*, int);

    /** Returns a cons cell whose car field is a and whose cdr is b. 
        @deprecated PtreeUtil */
    static Ptree* Cons(Ptree*, Ptree*);
    
    /*@{*/
    /** Creates a list @deprecated Use PtreeUtil */
    static Ptree* List();
    static Ptree* List(Ptree*);
    static Ptree* List(Ptree*, Ptree*);
    static Ptree* List(Ptree*, Ptree*, Ptree*);
    static Ptree* List(Ptree*, Ptree*, Ptree*, Ptree*);
    static Ptree* List(Ptree*, Ptree*, Ptree*, Ptree*, Ptree*);
    static Ptree* List(Ptree*, Ptree*, Ptree*, Ptree*, Ptree*, Ptree*);
    static Ptree* List(Ptree*, Ptree*, Ptree*, Ptree*, Ptree*, Ptree*,
		       Ptree*);
    static Ptree* List(Ptree*, Ptree*, Ptree*, Ptree*, Ptree*, Ptree*,
		       Ptree*, Ptree*);
    /*@}*/

    /** Returns a new list whose elements are the same as lst 's. @deprecated Use PtreeUtil */
    static Ptree* CopyList(Ptree*);
    
    /** @todo document */
    static Ptree* Append(Ptree*, Ptree*);
    
    /** Returns a list in which all occurrences of orig in lst are replaced with subst. This is not a destructive operation. 
        @deprecated Use PtreeUtil */
    static Ptree* ReplaceAll(Ptree*, Ptree*, Ptree*);


    /** @deprecated Use PtreeUtil  */
    static Ptree* Subst(Ptree*, Ptree*, Ptree*);

    /** @deprecated Use PtreeUtil  */
    static Ptree* Subst(Ptree*, Ptree*, Ptree*, Ptree*, Ptree*);

    /** @deprecated Use PtreeUtil  */
    static Ptree* Subst(Ptree*, Ptree*, Ptree*, Ptree*,
			Ptree*, Ptree*, Ptree*);

    /** @deprecated Use PtreeUtil  */
    static Ptree* ShallowSubst(Ptree*, Ptree*, Ptree*);

    /** @deprecated Use PtreeUtil  */
    static Ptree* ShallowSubst(Ptree*, Ptree*, Ptree*, Ptree*, Ptree*);

    /** @deprecated Use PtreeUtil  */
    static Ptree* ShallowSubst(Ptree*, Ptree*, Ptree*, Ptree*,
			       Ptree*, Ptree*, Ptree*);

    /** @deprecated Use PtreeUtil  */
    static Ptree* ShallowSubst(Ptree*, Ptree*, Ptree*, Ptree*,
			       Ptree*, Ptree*, Ptree*, Ptree*, Ptree*);

    /** @deprecated Use PtreeUtil  */
    static Ptree* SubstSublist(Ptree*, Ptree*, Ptree*);

    /** @deprecated Use PtreeUtil  */
    static Ptree* Snoc(Ptree*, Ptree*);

    /** @deprecated Use PtreeUtil  */
    static Ptree* Nconc(Ptree*, Ptree*);

    /** @deprecated Use PtreeUtil  */
    static Ptree* Nconc(Ptree*, Ptree*, Ptree*);

public:

    /** 
        Makes a Ptree metaobject according to the format. The format is
        a null-terminated string. All occurrences of %c (character), %d
        (integer), %s (character string), and %p (Ptree) in the format are
        replaced with the values following the format. %% in the format is
        replaced with %. 
      */
    static Ptree* Make(const char* pat, ...);

OPENCXX_DEPRECATED_PUBLIC:

    /** @deprecated Use PtreeUtil
      */
    static Ptree* GenSym();

    /** Makes a Ptree metaobject that represents the text. Any C++
        expression surrounded by backquotes can appear in text. Its
        occurrence is replaced with the value denoted by the expression. The
        type of the expression must be Ptree*, int, or char*.
        
        @deprecated Use PtreeUtil 
        */
    static Ptree* qMake(char*);

public:

    /** Returns true if the metaobject represents an integer constant. The
        denoted value is stored in value. Note that the denoted value is
        always a positive number because a negative number such as -4
        generates two distinct tokens such as - and 4.
     */
    bool Reify(unsigned int& value);

    /** Returns true if the metaobject represents a string literal. A
        string literal is a sequence of character surrounded by double
        quotes ". The denoted null-terminated string is stored in string. It
        does not include the double quotes at the both ends. Also, the
        escape sequences are not expanded.
     */
    bool Reify(char*& string);

protected:
    union {
	struct {
	    Ptree* child;
	    Ptree* next;
	} nonleaf;
	struct {
	    char* position;
	    int  length;
	} leaf;
    }data;

    friend class NonLeaf;
};

/** The operator << can be used to write a Ptree object to an output stream. It is equivalent to Write() in terms of the result.
 */
inline std::ostream& operator << (std::ostream& s, Ptree* p)
{
    p->Write(s);
    return s;
}

}

#endif /* ! guard_opencxx_Ptree_h */