summaryrefslogtreecommitdiff
path: root/cpp/src/Slice/Parser.h
blob: 096a3cab578fcfc14d06535a05a2572e1e25d7df (plain)
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
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
// **********************************************************************
//
// Copyright (c) 2001
// MutableRealms, Inc.
// Huntsville, AL, USA
//
// All Rights Reserved
//
// **********************************************************************

#ifndef PARSER_H
#define PARSER_H

#include <Ice/Shared.h>
#include <Ice/Handle.h>
#include <list>
#include <stack>
#include <map>

extern int yynerrs;

int yyparse();
int yylex();
void yyerror(const char* s);

// ----------------------------------------------------------------------
// Type_ptr declarations, reference counting, and handle types
// ----------------------------------------------------------------------

namespace Slice
{

class Token;
class String;
class Parameters;
class Throws;
class SyntaxTreeBase;
class Type;
class Builtin;
class Contained;
class Container;
class Module;
class Constructed;
class ClassDecl;
class ClassDef;
class Proxy;
class Operation;
class DataMember;
class Native;
class Vector;
class Parser;

}

namespace __Ice
{

void ICE_API incRef(::Slice::Token*);
void ICE_API decRef(::Slice::Token*);
void ICE_API incRef(::Slice::String*);
void ICE_API decRef(::Slice::String*);
void ICE_API incRef(::Slice::Parameters*);
void ICE_API decRef(::Slice::Parameters*);
void ICE_API incRef(::Slice::Throws*);
void ICE_API decRef(::Slice::Throws*);
void ICE_API incRef(::Slice::SyntaxTreeBase*);
void ICE_API decRef(::Slice::SyntaxTreeBase*);
void ICE_API incRef(::Slice::Type*);
void ICE_API decRef(::Slice::Type*);
void ICE_API incRef(::Slice::Builtin*);
void ICE_API decRef(::Slice::Builtin*);
void ICE_API incRef(::Slice::Contained*);
void ICE_API decRef(::Slice::Contained*);
void ICE_API incRef(::Slice::Container*);
void ICE_API decRef(::Slice::Container*);
void ICE_API incRef(::Slice::Module*);
void ICE_API decRef(::Slice::Module*);
void ICE_API incRef(::Slice::Constructed*);
void ICE_API decRef(::Slice::Constructed*);
void ICE_API incRef(::Slice::ClassDecl*);
void ICE_API decRef(::Slice::ClassDecl*);
void ICE_API incRef(::Slice::ClassDef*);
void ICE_API decRef(::Slice::ClassDef*);
void ICE_API incRef(::Slice::Proxy*);
void ICE_API decRef(::Slice::Proxy*);
void ICE_API incRef(::Slice::Operation*);
void ICE_API decRef(::Slice::Operation*);
void ICE_API incRef(::Slice::DataMember*);
void ICE_API decRef(::Slice::DataMember*);
void ICE_API incRef(::Slice::Native*);
void ICE_API decRef(::Slice::Native*);
void ICE_API incRef(::Slice::Vector*);
void ICE_API decRef(::Slice::Vector*);
void ICE_API incRef(::Slice::Parser*);
void ICE_API decRef(::Slice::Parser*);

}

namespace Slice
{

typedef ::__Ice::Handle<Token> Token_ptr;
typedef ::__Ice::Handle<String> String_ptr;
typedef ::__Ice::Handle<Parameters> Parameters_ptr;
typedef ::__Ice::Handle<Throws> Throws_ptr;
typedef ::__Ice::Handle<SyntaxTreeBase> SyntaxTreeBase_ptr;
typedef ::__Ice::Handle<Type> Type_ptr;
typedef ::__Ice::Handle<Builtin> Builtin_ptr;
typedef ::__Ice::Handle<Contained> Contained_ptr;
typedef ::__Ice::Handle<Container> Container_ptr;
typedef ::__Ice::Handle<Module> Module_ptr;
typedef ::__Ice::Handle<Constructed> Constructed_ptr;
typedef ::__Ice::Handle<ClassDecl> ClassDecl_ptr;
typedef ::__Ice::Handle<ClassDef> ClassDef_ptr;
typedef ::__Ice::Handle<Proxy> Proxy_ptr;
typedef ::__Ice::Handle<Operation> Operation_ptr;
typedef ::__Ice::Handle<DataMember> DataMember_ptr;
typedef ::__Ice::Handle<Native> Native_ptr;
typedef ::__Ice::Handle<Vector> Vector_ptr;
typedef ::__Ice::Handle<Parser> Parser_ptr;

}

namespace Slice
{

typedef std::list<Type_ptr> TypeList;
typedef std::pair<Type_ptr, std::string> TypeName;
typedef std::list<TypeName> TypeNameList;

// ----------------------------------------------------------------------
// ParserVisitor
// ----------------------------------------------------------------------

class ICE_API ParserVisitor
{
public:

    virtual ~ParserVisitor() { }
    virtual void visitUnitStart(const Parser_ptr&) { };
    virtual void visitUnitEnd(const Parser_ptr&) { };
    virtual void visitModuleStart(const Module_ptr&) { };
    virtual void visitModuleEnd(const Module_ptr&) { };
    virtual void visitClassDecl(const ClassDecl_ptr&) { };
    virtual void visitClassDefStart(const ClassDef_ptr&) { };
    virtual void visitClassDefEnd(const ClassDef_ptr&) { };
    virtual void visitOperation(const Operation_ptr&) { };
    virtual void visitDataMember(const DataMember_ptr&) { };
    virtual void visitVector(const Vector_ptr&) { };
    virtual void visitNative(const Native_ptr&) { };
};

// ----------------------------------------------------------------------
// Token
// ----------------------------------------------------------------------

class ICE_API Token : virtual public ::__Ice::SimpleShared
{
};

#define YYSTYPE Slice::Token_ptr

// ----------------------------------------------------------------------
// String
// ----------------------------------------------------------------------

class ICE_API String : virtual public Token
{
public:

    String() { }
    std::string v;
};

// ----------------------------------------------------------------------
// Parameters
// ----------------------------------------------------------------------

class ICE_API Parameters : virtual public Token
{
public:

    Parameters() { }
    TypeNameList v;
};

// ----------------------------------------------------------------------
// Throws
// ----------------------------------------------------------------------

class ICE_API Throws : virtual public Token
{
public:

    Throws() { }
    TypeList v;
};

// ----------------------------------------------------------------------
// SyntaxTreeBase
// ----------------------------------------------------------------------

class ICE_API SyntaxTreeBase : virtual public ::__Ice::SimpleShared
{
public:

    virtual void destroy();
    Parser_ptr parser();
    virtual void visit(ParserVisitor*);

protected:

    SyntaxTreeBase(const Parser_ptr&);

    Parser_ptr parser_;
};

// ----------------------------------------------------------------------
// Type
// ----------------------------------------------------------------------

class ICE_API Type : virtual public SyntaxTreeBase, virtual public Token
{
public:

protected:

    Type(const Parser_ptr&);
};

// ----------------------------------------------------------------------
// Builtin
// ----------------------------------------------------------------------

class ICE_API Builtin : virtual public Type
{
public:

    enum Kind
    {
	KindByte,
	KindBool,
	KindShort,
	KindInt,
	KindLong,
	KindFloat,
	KindDouble,
	KindString,
	KindWString,
	KindObject,
	KindObjectProxy,
	KindLocalObject
    };
    Kind kind();

protected:

    Builtin(const Parser_ptr&, Kind);
    friend class ICE_API Parser;

    Kind kind_;
};

// ----------------------------------------------------------------------
// Contained
// ----------------------------------------------------------------------

class ICE_API Contained : virtual public SyntaxTreeBase
{
public:

    Container_ptr container();
    std::string name();
    std::string scoped();
    std::string scope();

protected:

    Contained(const Container_ptr&,
	      const std::string&);
    friend class ICE_API Container;

    Container_ptr container_;
    std::string name_;
    std::string scoped_;
};

bool ICE_API operator<(Contained&, Contained&);
bool ICE_API operator==(Contained&, Contained&);

// ----------------------------------------------------------------------
// Container
// ----------------------------------------------------------------------

class ICE_API Container : virtual public SyntaxTreeBase
{
public:

    virtual void destroy();
    Module_ptr createModule(const std::string&);
    ClassDef_ptr createClassDef(const std::string&, const ClassDef_ptr&, bool);
    ClassDecl_ptr createClassDecl(const std::string&, bool);
    Vector_ptr createVector(const std::string&, const Type_ptr&);
    Native_ptr createNative(const std::string&);
    std::list<Type_ptr> lookupType(const std::string&);
    int includeLevel();
    bool hasProxies();
    bool hasClassDecls();
    bool hasClassDefs();
    bool hasOtherConstructedTypes(); // Other than classes
    std::string thisScope();
    void mergeModules();
    virtual void visit(ParserVisitor*);

protected:

    Container(const Parser_ptr&);

    int includeLevel_;
    std::list<Contained_ptr> contents_;
};

// ----------------------------------------------------------------------
// Module
// ----------------------------------------------------------------------

class ICE_API Module : virtual public Container, virtual public Contained
{
public:

    virtual void visit(ParserVisitor*);

protected:

    Module(const Container_ptr&,
	   const std::string&);
    friend class ICE_API Container;
};

// ----------------------------------------------------------------------
// Constructed
// ----------------------------------------------------------------------

class ICE_API Constructed : virtual public Type, virtual public Contained
{
public:

protected:

    Constructed(const Container_ptr&,
		const std::string&);
};

// ----------------------------------------------------------------------
// ClassDecl
// ----------------------------------------------------------------------

class ICE_API ClassDecl : virtual public Constructed
{
public:

    ClassDef_ptr definition();
    bool local();
    virtual void visit(ParserVisitor*);

protected:

    ClassDecl(const Container_ptr&,
	      const std::string&,
	      bool);
    friend class ICE_API Container;
    friend class ICE_API ClassDef;

    bool local_;
    ClassDef_ptr definition_;
};

// ----------------------------------------------------------------------
// ClassDef
// ----------------------------------------------------------------------

class ICE_API ClassDef : virtual public Container, virtual public Contained,
		 virtual public Token 
{
public:

    virtual void destroy();
    Operation_ptr createOperation(const std::string&, const Type_ptr&,
				  const TypeNameList&, const TypeNameList&,
				  const TypeList&);
    DataMember_ptr createDataMember(const std::string&, const Type_ptr&);
    ClassDef_ptr base();
    std::list<Operation_ptr> operations();
    std::list<DataMember_ptr> dataMembers();
    bool abstract();
    bool local();
    virtual void visit(ParserVisitor*);

protected:

    ClassDef(const Container_ptr&,
	     const std::string&,
	     const ClassDef_ptr&,
	     bool);
    friend class ICE_API Container;

    ClassDef_ptr base_;
    bool local_;
};

// ----------------------------------------------------------------------
// Proxy
// ----------------------------------------------------------------------

class ICE_API Proxy : virtual public Type
{
public:

    ClassDecl_ptr _class();

    Proxy(const ClassDecl_ptr&);

protected:

    ClassDecl_ptr class_;
};

// ----------------------------------------------------------------------
// Operation
// ----------------------------------------------------------------------

class ICE_API Operation : virtual public Contained
{
public:

    Type_ptr returnType();
    TypeNameList inputParameters();
    TypeNameList outputParameters();
    TypeList throws();
    virtual void visit(ParserVisitor*);

protected:

    Operation(const Container_ptr&,
	      const std::string&,
	      const Type_ptr&,
	      const TypeNameList&,
	      const TypeNameList&,
	      const TypeList&);
    friend class ICE_API ClassDef;

    Type_ptr returnType_;
    TypeNameList inParams_;
    TypeNameList outParams_;
    TypeList throws_;
};

// ----------------------------------------------------------------------
// DataMember
// ----------------------------------------------------------------------

class ICE_API DataMember : virtual public Contained
{
public:

    Type_ptr type();
    virtual void visit(ParserVisitor*);

protected:
    
    DataMember(const Container_ptr&,
	       const std::string&,
	       const Type_ptr&);
    friend class ICE_API ClassDef;

    Type_ptr type_;
};

// ----------------------------------------------------------------------
// Native
// ----------------------------------------------------------------------

class Native : virtual public Constructed
{
public:

    virtual void visit(ParserVisitor*);

protected:

    Native(const Container_ptr&,
	   const std::string&);
    friend class Container;
};

// ----------------------------------------------------------------------
// Vector
// ----------------------------------------------------------------------

class ICE_API Vector : virtual public Constructed
{
public:

    Type_ptr type();
    virtual void visit(ParserVisitor*);

protected:

    Vector(const Container_ptr&,
	   const std::string&,
	   const Type_ptr&);
    friend class ICE_API Container;

    Type_ptr type_;
};

// ----------------------------------------------------------------------
// Parser
// ----------------------------------------------------------------------

class ICE_API Parser : virtual public Container
{
public:

    static Parser_ptr createParser();

    void nextLine();
    void scanPosition(const char*);
    int currentIncludeLevel();

    void error(const char*);
    void warning(const char*);

    Container_ptr currentContainer();
    void pushContainer(const Container_ptr&);
    void popContainer();

    void addContent(const Contained_ptr&);
    void removeContent(const Contained_ptr&);
    std::list<Contained_ptr> findContents(const std::string&);

    std::list<std::string> includeFiles();

    int parse(FILE*, bool);

    virtual void destroy();
    virtual void visit(ParserVisitor*);

    Builtin_ptr builtin(Builtin::Kind);

private:

    Parser();

    int currentLine_;
    int currentIncludeLevel_;
    std::string currentFile_;
    std::string topLevelFile_;
    std::list<std::string> includeFiles_;
    std::stack<Container_ptr> containerStack_;
    std::map<Builtin::Kind, Builtin_ptr> builtins_;
    std::map<std::string, std::list<Contained_ptr> > contentMap_;
};

extern Parser* parser; // The current parser for bison/flex

}

#endif