Synopsis - Cross-Reference

File: /Synopsis/Parsers/IDL/idlast.h
   1// -*- c++ -*-
   2//                          Package   : omniidl
   3// idlast.h                 Created on: 1999/10/07
   4//			    Author    : Duncan Grisby (dpg1)
   5//
   6//    Copyright (C) 1999 AT&T Laboratories Cambridge
   7//
   8//  This file is part of omniidl.
   9//
  10//  omniidl is free software; you can redistribute it and/or modify it
  11//  under the terms of the GNU General Public License as published by
  12//  the Free Software Foundation; either version 2 of the License, or
  13//  (at your option) any later version.
  14//
  15//  This program is distributed in the hope that it will be useful,
  16//  but WITHOUT ANY WARRANTY; without even the implied warranty of
  17//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  18//  General Public License for more details.
  19//
  20//  You should have received a copy of the GNU General Public License
  21//  along with this program; if not, write to the Free Software
  22//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  23//  02111-1307, USA.
  24//
  25// Description:
  26//   
  27//   Definitions for abstract syntax tree classes
  28
  29// $Id: idlast.h,v 1.15.2.3 2004/02/16 10:10:33 dgrisby Exp $
  30// $Log: idlast.h,v $
  31// Revision 1.15.2.3  2004/02/16 10:10:33  dgrisby
  32// More valuetype, including value boxes. C++ mapping updates.
  33//
  34// Revision 1.15.2.2  2003/09/04 14:00:24  dgrisby
  35// ValueType IDL updates.
  36//
  37// Revision 1.15.2.1  2003/03/23 21:01:47  dgrisby
  38// Start of omniORB 4.1.x development branch.
  39//
  40// Revision 1.10.2.6  2001/08/29 11:55:23  dpg1
  41// Enumerator nodes record their value.
  42//
  43// Revision 1.10.2.5  2001/03/13 10:32:11  dpg1
  44// Fixed point support.
  45//
  46// Revision 1.10.2.4  2000/11/01 12:45:56  dpg1
  47// Update to CORBA 2.4 specification.
  48//
  49// Revision 1.10.2.3  2000/10/27 16:31:08  dpg1
  50// Clean up of omniidl dependencies and types, from omni3_develop.
  51//
  52// Revision 1.10.2.2  2000/10/10 10:18:50  dpg1
  53// Update omniidl front-end from omni3_develop.
  54//
  55// Revision 1.8.2.6  2000/08/29 10:20:26  dpg1
  56// Operations and attributes now have repository ids.
  57//
  58// Revision 1.8.2.5  2000/08/04 11:39:03  dpg1
  59// Updates for AIX with xlC
  60//
  61// Revision 1.8.2.4  2000/06/08 14:36:19  dpg1
  62// Comments and pragmas are now objects rather than plain strings, so
  63// they can have file,line associated with them.
  64//
  65// Revision 1.8.2.3  2000/06/05 18:13:27  dpg1
  66// Comments can be attached to subsequent declarations (with -K). Better
  67// idea of most recent decl in operation declarations
  68//
  69// Revision 1.8.2.2  2000/03/07 10:36:38  dpg1
  70// More sensible idea of the "most recent" declaration.
  71//
  72// Revision 1.8.2.1  2000/03/06 15:03:48  dpg1
  73// Minor bug fixes to omniidl. New -nf and -k flags.
  74//
  75// Revision 1.8  2000/02/04 12:17:09  dpg1
  76// Support for VMS.
  77//
  78// Revision 1.7  1999/11/17 17:17:00  dpg1
  79// Changes to remove static initialisation of objects.
  80//
  81// Revision 1.6  1999/11/02 17:07:27  dpg1
  82// Changes to compile on Solaris.
  83//
  84// Revision 1.5  1999/11/01 20:19:56  dpg1
  85// Support for union switch types declared inside the switch statement.
  86//
  87// Revision 1.4  1999/11/01 10:05:01  dpg1
  88// New file attribute to AST.
  89//
  90// Revision 1.3  1999/10/29 15:43:02  dpg1
  91// Code to detect recursive structs and unions.
  92//
  93// Revision 1.2  1999/10/29 10:00:43  dpg1
  94// Added code to find a value for the default case in a union.
  95//
  96// Revision 1.1  1999/10/27 14:05:59  dpg1
  97// *** empty log message ***
  98//
  99
 100#ifndef _idlast_h_
 101#define _idlast_h_
 102
 103#include <idlutil.h>
 104#include <idltype.h>
 105#include <idlexpr.h>
 106#include <idlscope.h>
 107#include <idlvisitor.h>
 108
 109#include <stdio.h>
 110
 111int yyparse();
 112class Decl;
 113
 114// Pragma class stores a list of pragmas:
 115class Pragma {
 116public:
 117  Pragma(const char* pragmaText, const char* file, int line)
 118    : pragmaText_(idl_strdup(pragmaText)),
 119      file_(idl_strdup(file)), line_(line), next_(0) {}
 120
 121  ~Pragma() {
 122    delete [] pragmaText_;
 123    delete [] file_;
 124    if (next_) delete next_;
 125  }
 126
 127  const char* pragmaText() const { return pragmaText_; }
 128  const char* file()       const { return file_; }
 129  int         line()       const { return line_; }
 130  Pragma*     next()       const { return next_; }
 131
 132  static void add(const char* pragmaText, const char* file, int line);
 133
 134private:
 135  char*   pragmaText_;
 136  char*   file_;
 137  int     line_;
 138  Pragma* next_;
 139
 140  friend class AST;
 141  friend class Decl;
 142};
 143
 144// Comment class stores a list of comment strings:
 145class Comment {
 146public:
 147  Comment(const char* commentText, const char* file, int line)
 148    : commentText_(idl_strdup(commentText)),
 149      file_(idl_strdup(file)), line_(line), next_(0) {
 150    mostRecent_ = this;
 151  }
 152
 153  ~Comment() {
 154    delete [] commentText_;
 155    delete [] file_;
 156    if (next_) delete next_;
 157  }
 158
 159  const char* commentText() const { return commentText_; }
 160  const char* file()        const { return file_; }
 161  int         line()        const { return line_; }
 162  Comment*    next()        const { return next_; }
 163
 164  static void add   (const char* commentText, const char* file, int line);
 165  static void append(const char* commentText);
 166  static void clear() { mostRecent_ = 0; }
 167
 168  static Comment* grabSaved();
 169  // Return any saved comments, and clear the saved comment list
 170
 171private:
 172  char*           commentText_;
 173  char*           file_;
 174  int             line_;
 175  Comment*        next_;
 176  static Comment* mostRecent_;
 177  static Comment* saved_;
 178
 179  friend class AST;
 180  friend class Decl;
 181};
 182
 183
 184
 185// AST class represents the whole IDL definition
 186class AST {
 187public:
 188  AST();
 189  ~AST();
 190  static AST*        tree();
 191  static IDL_Boolean process(FILE* f, const char* name);
 192  static void        clear();
 193
 194  Decl*       declarations()              { return declarations_; }
 195  const char* file()                      { return file_; }
 196  Pragma*     pragmas()                   { return pragmas_; }
 197  Comment*    comments()                  { return comments_; }
 198
 199  void        accept(AstVisitor& visitor) { visitor.visitAST(this); }
 200
 201  void        setFile(const char* f);
 202  void        addPragma(const char* pragmaText, const char* file, int line);
 203  void        addComment(const char* commentText, const char* file, int line);
 204
 205private:
 206  void        setDeclarations(Decl* d);
 207
 208  Decl*       declarations_;
 209  char*       file_;
 210  static AST* tree_;
 211  Pragma*     pragmas_;
 212  Pragma*     lastPragma_;
 213  Comment*    comments_;
 214  Comment*    lastComment_;
 215  friend int  yyparse();
 216};
 217
 218
 219// Base declaration abstract class
 220class Decl {
 221public:
 222  // Declaration kinds
 223  enum Kind {
 224    D_MODULE, D_INTERFACE, D_FORWARD, D_CONST, D_DECLARATOR,
 225    D_TYPEDEF, D_MEMBER, D_STRUCT, D_STRUCTFORWARD, D_EXCEPTION,
 226    D_CASELABEL, D_UNIONCASE, D_UNION, D_UNIONFORWARD,
 227    D_ENUMERATOR, D_ENUM, D_ATTRIBUTE, D_PARAMETER, D_OPERATION,
 228    D_NATIVE, D_STATEMEMBER, D_FACTORY, D_VALUEFORWARD, D_VALUEBOX,
 229    D_VALUEABS, D_VALUE
 230  };
 231
 232  Decl(Kind kind, const char* file, int line, IDL_Boolean mainFile);
 233  virtual ~Decl();
 234
 235  // Declaration kind
 236  Kind                kind()         const { return kind_; }
 237  virtual const char* kindAsString() const = 0;
 238
 239  // Query interface
 240  const char*       file()       const { return file_; }
 241  int               line()       const { return line_; }
 242  IDL_Boolean       mainFile()   const { return mainFile_; }
 243  const Scope*      inScope()    const { return inScope_; }
 244  const Pragma*     pragmas()    const { return pragmas_; }
 245  const Comment*    comments()   const { return comments_; }
 246
 247  // Linked list
 248  Decl* next() { return next_; }
 249
 250  void append(Decl* d) {
 251    if (d) {
 252      last_->next_ = d;
 253      last_        = d;
 254    }
 255  }
 256
 257  // Find a decl given a name. Does not mark the name used.
 258  static Decl* scopedNameToDecl(const char* file, int line,
 259				const ScopedName* sn);
 260
 261  static Decl* mostRecent() { return mostRecent_; }
 262  static void  clear()      { mostRecent_ = 0; }
 263
 264  // Visitor pattern accept(). The visitor is responsible for
 265  // recursively visiting children if it needs to
 266  virtual void accept(AstVisitor& visitor) = 0;
 267
 268  void addPragma(const char* pragmaText, const char* file, int line);
 269  void addComment(const char* commentText, const char* file, int line);
 270
 271private:
 272  Kind              kind_;
 273  char*             file_;
 274  int               line_;
 275  IDL_Boolean       mainFile_;
 276  const Scope*      inScope_;
 277  Pragma*           pragmas_;
 278  Pragma*           lastPragma_;
 279  Comment*          comments_;
 280  Comment*          lastComment_;
 281
 282protected:
 283  static Decl*      mostRecent_;
 284
 285  Decl* next_;
 286  Decl* last_;
 287};
 288
 289
 290// Mixin class for Decls with a RepoId
 291class DeclRepoId {
 292public:
 293  DeclRepoId(const char* identifier);
 294  ~DeclRepoId();
 295
 296  // eidentifier() returns the identifier with _ escapes intact
 297  const char*       identifier()  const { return identifier_; }
 298  const char*       eidentifier() const { return eidentifier_; }
 299  const ScopedName* scopedName()  const { return scopedName_; }
 300  const char*       repoId()      const { return repoId_; }
 301  const char*       prefix()      const { return prefix_; }
 302
 303  void setRepoId(const char* repoId, const char* file, int line);
 304  void setVersion(IDL_Short maj, IDL_Short min,
 305		  const char* file, int line);
 306
 307  // Static set functions taking a Decl as an argument
 308  static void setRepoId(Decl* d, const char* repoId,
 309			const char* file, int line);
 310  static void setVersion(Decl* d, IDL_Short maj, IDL_Short min,
 311			 const char* file, int line);
 312
 313  IDL_Boolean repoIdSet() const { return set_; }
 314  const char* rifile()    const { return rifile_; }
 315  int         riline()    const { return riline_; }
 316  IDL_Short   rimaj()     const { return maj_; }
 317  IDL_Short   rimin()     const { return min_; }
 318
 319private:
 320  void genRepoId();
 321
 322  char*          identifier_;
 323  char*          eidentifier_;
 324  ScopedName*    scopedName_;
 325  char*          repoId_;
 326  char*          prefix_; // Prefix in force at time of declaration
 327  IDL_Boolean    set_;    // True if repoId or version has been manually set
 328  char*          rifile_; // File where repoId or version was set
 329  int            riline_; // Line where repoId or version was set
 330  IDL_Short      maj_;
 331  IDL_Short      min_;
 332};
 333
 334
 335// Module
 336class Module : public Decl, public DeclRepoId {
 337public:
 338  Module(const char* file, int line, IDL_Boolean mainFile,
 339	 const char* identifier);
 340
 341  virtual ~Module();
 342
 343  const char* kindAsString() const { return "module"; }
 344
 345  // Query interface
 346  Decl* definitions() const { return definitions_; }
 347  
 348  void accept(AstVisitor& visitor) { visitor.visitModule(this); }
 349
 350  void finishConstruction(Decl* defs);
 351
 352private:
 353  Decl*  definitions_;
 354};
 355
 356
 357// List of inherited interfaces
 358class InheritSpec {
 359public:
 360  InheritSpec(const ScopedName* sn, const char* file, int line);
 361
 362  ~InheritSpec() { if (next_) delete next_; }
 363
 364  // The ScopedName used in an inheritance specification may be a
 365  // typedef. In that case, decl() returns the Typedef declarator
 366  // object and interface() returns the actual Interface object.
 367  // Otherwise, both functions return the same Interface pointer.
 368
 369  Interface*   interface() const { return interface_; }
 370  Decl*        decl()      const { return decl_; }
 371  const Scope* scope()     const { return scope_; }
 372  InheritSpec* next()      const { return next_; }
 373
 374  void append(InheritSpec* is, const char* file, int line);
 375
 376private:
 377  Interface*   interface_;
 378  Decl*        decl_;
 379  const Scope* scope_;
 380
 381protected:
 382  InheritSpec* next_;
 383};
 384
 385
 386
 387// Interface
 388class Interface : public Decl, public DeclRepoId {
 389public:
 390  Interface(const char* file, int line, IDL_Boolean mainFile,
 391	    const char* identifier, IDL_Boolean abstract,
 392	    IDL_Boolean local, InheritSpec* inherits);
 393
 394  virtual ~Interface();
 395
 396  const char* kindAsString() const { return "interface"; }
 397
 398  // Queries
 399  IDL_Boolean    abstract() const { return abstract_; }
 400  IDL_Boolean    local()    const { return local_;    }
 401  InheritSpec*   inherits() const { return inherits_; }
 402  Decl*          contents() const { return contents_; }
 403  Scope*         scope()    const { return scope_;    }
 404  IdlType*       thisType() const { return thisType_; }
 405
 406  IDL_Boolean    isDerived(const Interface* base) const;
 407
 408  void accept(AstVisitor& visitor) { visitor.visitInterface(this); }
 409
 410  void finishConstruction(Decl* decls);
 411
 412private:
 413  IDL_Boolean    abstract_;
 414  IDL_Boolean    local_;
 415  InheritSpec*   inherits_;
 416  Decl*          contents_;
 417  Scope*         scope_;
 418  IdlType*       thisType_;
 419};
 420
 421
 422// Forward-declared interface
 423class Forward : public Decl, public DeclRepoId {
 424public:
 425  Forward(const char* file, int line, IDL_Boolean mainFile,
 426	  const char* identifier, IDL_Boolean abstract, IDL_Boolean local);
 427
 428  virtual ~Forward();
 429
 430  const char* kindAsString() const { return "forward interface"; }
 431
 432  // Query interface
 433  IDL_Boolean    abstract()   const { return abstract_; }
 434  IDL_Boolean    local()      const { return local_;    }
 435  Interface*     definition() const;
 436  IDL_Boolean    isFirst()    const { return !firstForward_; }
 437  IdlType*       thisType()   const { return thisType_; }
 438
 439  void accept(AstVisitor& visitor) { visitor.visitForward(this); }
 440
 441  void setDefinition(Interface* defn);
 442
 443private:
 444  IDL_Boolean    abstract_;
 445  IDL_Boolean    local_;
 446  Interface*     definition_;
 447  Forward*       firstForward_;
 448  IdlType*       thisType_;
 449};
 450
 451
 452// Constant
 453class Const : public Decl, public DeclRepoId {
 454public:
 455  Const(const char* file, int line, IDL_Boolean mainFile,
 456	IdlType* constType, const char* identifier, IdlExpr* expr);
 457
 458  virtual ~Const();
 459
 460  const char* kindAsString() const { return "constant"; }
 461
 462  // Queries
 463  IdlType*      constType() const { return constType_; }
 464  IdlType::Kind constKind() const { return constKind_; }
 465
 466  IDL_Short        constAsShort()      const;
 467  IDL_Long         constAsLong()       const;
 468  IDL_UShort       constAsUShort()     const;
 469  IDL_ULong        constAsULong()      const;
 470  IDL_Float        constAsFloat()      const;
 471  IDL_Double       constAsDouble()     const;
 472  IDL_Boolean      constAsBoolean()    const;
 473  IDL_Char         constAsChar()       const;
 474  IDL_Octet        constAsOctet()      const;
 475  const char*      constAsString()     const;
 476#ifdef HAS_LongLong
 477  IDL_LongLong     constAsLongLong()   const;
 478  IDL_ULongLong    constAsULongLong()  const;
 479#endif
 480#ifdef HAS_LongDouble
 481  IDL_LongDouble   constAsLongDouble() const;
 482#endif
 483  IDL_WChar        constAsWChar()      const;
 484  const IDL_WChar* constAsWString()    const;
 485  IDL_Fixed*       constAsFixed()      const;
 486  Enumerator*      constAsEnumerator() const;
 487
 488  void accept(AstVisitor& visitor) { visitor.visitConst(this); }
 489
 490private:
 491  IdlType*       constType_;
 492  IDL_Boolean    delType_;
 493  IdlType::Kind  constKind_;
 494  union {
 495    IDL_Short        short_;
 496    IDL_Long         long_;
 497    IDL_UShort       ushort_;
 498    IDL_ULong        ulong_;
 499#ifndef __VMS
 500    IDL_Float        float_;
 501    IDL_Double       double_;
 502#else
 503    float            float_;
 504    double           double_;
 505#endif
 506    IDL_Boolean      boolean_;
 507    IDL_Char         char_;
 508    IDL_Octet        octet_;
 509    char*            string_;
 510#ifdef HAS_LongLong
 511    IDL_LongLong     longlong_;
 512    IDL_ULongLong    ulonglong_;
 513#endif
 514#ifdef HAS_LongDouble
 515    IDL_LongDouble   longdouble_;
 516#endif
 517    IDL_WChar        wchar_;
 518    IDL_WChar*       wstring_;
 519    IDL_Fixed*       fixed_;
 520    Enumerator*      enumerator_;
 521  } v_;
 522};
 523
 524
 525// Typedef
 526
 527class ArraySize {
 528public:
 529  ArraySize(int size) : size_(size), next_(0), last_(0) {}
 530
 531  ~ArraySize() { if (next_) delete next_; }
 532
 533  int size()        const { return size_; }
 534  ArraySize* next() const { return next_; }
 535
 536  void append(ArraySize* as) {
 537    if (last_) last_->next_ = as;
 538    else       next_ = as;
 539    last_ = as;
 540  }
 541
 542private:
 543  int size_;
 544
 545protected:
 546  ArraySize* next_;
 547  ArraySize* last_;
 548};
 549
 550
 551class Typedef;
 552class Attribute;
 553
 554class Declarator : public Decl, public DeclRepoId {
 555public:
 556  Declarator(const char* file, int line, IDL_Boolean mainFile,
 557	     const char* identifier, ArraySize* sizes);
 558
 559  virtual ~Declarator();
 560
 561  const char* kindAsString() const;
 562
 563  // Queries
 564  ArraySize* sizes()    const { return sizes_; }
 565				// Null if a simple declarator
 566
 567  // Only for typedef declarators
 568  IdlType*   thisType()  const { return thisType_; }
 569  Typedef*   alias()     const { return alias_; } 
 570  Attribute* attribute() const { return attribute_; }
 571
 572  void accept(AstVisitor& visitor) { visitor.visitDeclarator(this); }
 573
 574  void setAlias    (Typedef*   td);
 575  void setAttribute(Attribute* at);
 576
 577private:
 578  ArraySize*  sizes_;
 579  IdlType*    thisType_;
 580  Typedef*    alias_;
 581  Attribute*  attribute_;
 582};
 583
 584
 585class Typedef : public Decl {
 586public:
 587  Typedef(const char* file, int line, IDL_Boolean mainFile,
 588	  IdlType* aliasType, IDL_Boolean constrType,
 589	  Declarator* declarators);
 590
 591  virtual ~Typedef();
 592
 593  const char* kindAsString() const { return "typedef"; }
 594
 595  // Queries
 596  IdlType*       aliasType()   const { return aliasType_; }
 597  IDL_Boolean    constrType()  const { return constrType_; }
 598  Declarator*    declarators() const { return declarators_; }
 599
 600  void accept(AstVisitor& visitor) { visitor.visitTypedef(this); }
 601
 602private:
 603  IdlType*       aliasType_;
 604  IDL_Boolean    delType_;
 605  IDL_Boolean    constrType_;
 606  Declarator*    declarators_;
 607};
 608
 609
 610// Struct member
 611class Member : public Decl {
 612public:
 613  Member(const char* file, int line, IDL_Boolean mainFile,
 614	 IdlType* memberType, IDL_Boolean constrType,
 615	 Declarator* declarators);
 616  virtual ~Member();
 617
 618  const char* kindAsString() const { return "member"; }
 619
 620  // Queries
 621  IdlType*       memberType()  const { return memberType_; }
 622  IDL_Boolean    constrType()  const { return constrType_; }
 623  Declarator*    declarators() const { return declarators_; }
 624
 625  void accept(AstVisitor& visitor) { visitor.visitMember(this); }
 626
 627private:
 628  IdlType*       memberType_;
 629  IDL_Boolean    delType_;
 630  IDL_Boolean    constrType_;
 631  Declarator*    declarators_;
 632};
 633
 634
 635
 636// Struct
 637class Struct : public Decl, public DeclRepoId {
 638public:
 639  Struct(const char* file, int line, IDL_Boolean mainFile,
 640	 const char* identifier);
 641  virtual ~Struct();
 642
 643  const char* kindAsString() const { return "struct"; }
 644
 645  // Queries
 646  Member*        members()   const { return members_; }
 647  IdlType*       thisType()  const { return thisType_; }
 648  IDL_Boolean    recursive() const { return recursive_; }
 649  IDL_Boolean    finished()  const { return finished_; }
 650
 651  void accept(AstVisitor& visitor) { visitor.visitStruct(this); }
 652
 653  void finishConstruction(Member* members);
 654
 655  void setRecursive() { recursive_ = 1; }
 656
 657private:
 658  Member*        members_;
 659  IdlType*       thisType_;
 660  IDL_Boolean    recursive_;
 661  IDL_Boolean    finished_;
 662};
 663
 664// Forward-declared struct
 665class StructForward : public Decl, public DeclRepoId {
 666public:
 667  StructForward(const char* file, int line, IDL_Boolean mainFile,
 668		const char* identifier);
 669  virtual ~StructForward();
 670
 671  const char* kindAsString()  const { return "forward struct"; }
 672
 673  // Queries
 674  Struct*        definition() const;
 675  IDL_Boolean    isFirst()    const { return !firstForward_; }
 676  IdlType*       thisType()   const { return thisType_; }
 677
 678  void accept(AstVisitor& visitor) { visitor.visitStructForward(this); }
 679
 680  void setDefinition(Struct* defn);
 681
 682private:
 683  Struct*        definition_;
 684  StructForward* firstForward_;
 685  IdlType*       thisType_;
 686};
 687
 688
 689// Exception
 690class Exception : public Decl, public DeclRepoId {
 691public:
 692  Exception(const char* file, int line, IDL_Boolean mainFile,
 693	    const char* identifier);
 694  virtual ~Exception();
 695
 696  const char* kindAsString() const { return "exception"; }
 697
 698  // Queries
 699  Member*        members()  const { return members_; }
 700  IDL_Boolean    local()    const { return local_; }
 701
 702  void accept(AstVisitor& visitor) { visitor.visitException(this); }
 703
 704  void finishConstruction(Member* members);
 705
 706private:
 707  Member*        members_;
 708  IDL_Boolean    local_;
 709};
 710
 711
 712// Union case label
 713class CaseLabel : public Decl {
 714public:
 715  CaseLabel(const char* file, int line, IDL_Boolean mainFile,
 716	    IdlExpr* value);
 717  virtual ~CaseLabel();
 718
 719  const char* kindAsString() const { return "case label"; }
 720
 721  IDL_Short        labelAsShort()      const;
 722  IDL_Long         labelAsLong()       const;
 723  IDL_UShort       labelAsUShort()     const;
 724  IDL_ULong        labelAsULong()      const;
 725  IDL_Boolean      labelAsBoolean()    const;
 726  IDL_Char         labelAsChar()       const;
 727#ifdef HAS_LongLong
 728  IDL_LongLong     labelAsLongLong()   const;
 729  IDL_ULongLong    labelAsULongLong()  const;
 730#endif
 731  IDL_WChar        labelAsWChar()      const;
 732  Enumerator*      labelAsEnumerator() const;
 733
 734  inline IDL_Boolean isDefault() const { return isDefault_; }
 735  IdlType::Kind      labelKind() const { return labelKind_; }
 736
 737  void accept(AstVisitor& visitor) { visitor.visitCaseLabel(this); }
 738
 739  void setType(IdlType* type);
 740  void setDefaultShort     (IDL_Short     v) { v_.short_      = v; }
 741  void setDefaultLong      (IDL_Long      v) { v_.long_       = v; }
 742  void setDefaultUShort    (IDL_UShort    v) { v_.ushort_     = v; }
 743  void setDefaultULong     (IDL_ULong     v) { v_.ulong_      = v; }
 744  void setDefaultBoolean   (IDL_Boolean   v) { v_.boolean_    = v; }
 745  void setDefaultChar      (IDL_Char      v) { v_.char_       = v; }
 746#ifdef HAS_LongLong
 747  void setDefaultLongLong  (IDL_LongLong  v) { v_.longlong_   = v; }
 748  void setDefaultULongLong (IDL_ULongLong v) { v_.ulonglong_  = v; }
 749#endif
 750  void setDefaultWChar     (IDL_WChar     v) { v_.wchar_      = v; }
 751  void setDefaultEnumerator(Enumerator*   v) { v_.enumerator_ = v; }
 752
 753private:
 754  IdlExpr*       value_;
 755  IDL_Boolean isDefault_;
 756  IdlType::Kind  labelKind_;
 757  union {
 758    IDL_Short        short_;
 759    IDL_Long         long_;
 760    IDL_UShort       ushort_;
 761    IDL_ULong        ulong_;
 762    IDL_Boolean      boolean_;
 763    IDL_Char         char_;
 764#ifdef HAS_LongLong
 765    IDL_LongLong     longlong_;
 766    IDL_ULongLong    ulonglong_;
 767#endif
 768    IDL_WChar        wchar_;
 769    Enumerator*      enumerator_;
 770  } v_;
 771};
 772
 773
 774// Union case
 775class UnionCase : public Decl {
 776public:
 777  UnionCase(const char* file, int line, IDL_Boolean mainFile,
 778	    IdlType* caseType, IDL_Boolean constrType,
 779	    Declarator* declarator);
 780  virtual ~UnionCase();
 781
 782  const char* kindAsString() const { return "case"; }
 783
 784  // Queries
 785  CaseLabel*     labels()     const { return labels_; }
 786  IdlType*       caseType()   const { return caseType_; }
 787  IDL_Boolean    constrType() const { return constrType_; }
 788  Declarator*    declarator() const { return declarator_; }
 789
 790  void accept(AstVisitor& visitor) { visitor.visitUnionCase(this); }
 791
 792  void finishConstruction(CaseLabel* labels);
 793
 794private:
 795  CaseLabel*     labels_;
 796  IdlType*       caseType_;
 797  IDL_Boolean    delType_;
 798  IDL_Boolean    constrType_;
 799  Declarator*    declarator_;
 800};
 801
 802
 803// Union
 804class Union : public Decl, public DeclRepoId {
 805public:
 806  Union(const char* file, int line, IDL_Boolean mainFile,
 807	const char* identifier);
 808  virtual ~Union();
 809
 810  const char* kindAsString() const { return "union"; }
 811
 812  // Queries
 813  IdlType*       switchType() const { return switchType_; }
 814  IDL_Boolean    constrType() const { return constrType_; }
 815  UnionCase*     cases()      const { return cases_; }
 816  IdlType*       thisType()   const { return thisType_; }
 817  IDL_Boolean    recursive()  const { return recursive_; }
 818  IDL_Boolean    finished()   const { return finished_; }
 819
 820  void accept(AstVisitor& visitor) { visitor.visitUnion(this); }
 821
 822  void finishConstruction(IdlType* switchType, IDL_Boolean constrType,
 823			  UnionCase* cases);
 824  void setRecursive() { recursive_ = 1; }
 825
 826private:
 827  IdlType*       switchType_;
 828  IDL_Boolean    constrType_;
 829  UnionCase*     cases_;
 830  IdlType*       thisType_;
 831  IDL_Boolean    recursive_;
 832  IDL_Boolean    finished_;
 833};
 834
 835class UnionForward : public Decl, public DeclRepoId {
 836public:
 837  UnionForward(const char* file, int line, IDL_Boolean mainFile,
 838	       const char* identifier);
 839  virtual ~UnionForward();
 840
 841  const char* kindAsString() const { return "forward union"; }
 842
 843  // Queries
 844  Union*      definition() const;
 845  IDL_Boolean isFirst()    const { return !firstForward_; }
 846  IdlType*    thisType()   const { return thisType_; }
 847
 848  void accept(AstVisitor& visitor) { visitor.visitUnionForward(this); }
 849
 850  void setDefinition(Union* defn);
 851
 852private:
 853  Union*        definition_;
 854  UnionForward* firstForward_;
 855  IdlType*      thisType_;
 856};
 857
 858
 859// Enumerator
 860class Enum;
 861
 862class Enumerator : public Decl, public DeclRepoId {
 863public:
 864  Enumerator(const char* file, int line, IDL_Boolean mainFile,
 865	     const char* identifier);
 866  virtual ~Enumerator();
 867
 868  const char* kindAsString() const { return "enumerator"; }
 869
 870  // Queries
 871  Enum*       container()  const { return container_; }
 872  IDL_ULong   value()      const { return value_; }
 873
 874  void accept(AstVisitor& visitor) { visitor.visitEnumerator(this); }
 875
 876  void finishConstruction(Enum* container, IDL_ULong value);
 877
 878private:
 879  const char* identifier_;
 880  Enum*       container_;
 881  IDL_ULong   value_;
 882};
 883
 884
 885// Enum
 886class Enum : public Decl, public DeclRepoId {
 887public:
 888  Enum(const char* file, int line, IDL_Boolean mainFile,
 889       const char* identifier);
 890  virtual ~Enum();
 891
 892  const char* kindAsString() const { return "enum"; }
 893
 894  // Queries
 895  Enumerator* enumerators() const { return enumerators_; }
 896  IdlType*    thisType()    const { return thisType_; }
 897
 898  void accept(AstVisitor& visitor) { visitor.visitEnum(this); }
 899
 900  void finishConstruction(Enumerator* enumerators);
 901
 902private:
 903  Enumerator* enumerators_;
 904  IdlType*    thisType_;
 905};
 906
 907
 908
 909// Attribute
 910class Attribute : public Decl {
 911public:
 912  Attribute(const char* file, int line, IDL_Boolean mainFile,
 913	    IDL_Boolean readonly, IdlType* attrType,
 914	    Declarator* declarators);
 915  virtual ~Attribute();
 916
 917  const char* kindAsString() const { return "attribute"; }
 918
 919  // Queries
 920  IDL_Boolean    readonly()    const { return readonly_; }
 921  IdlType*       attrType()    const { return attrType_; }
 922  Declarator*    declarators() const { return declarators_; }
 923
 924  void accept(AstVisitor& visitor) { visitor.visitAttribute(this); }
 925
 926private:
 927  IDL_Boolean    readonly_;
 928  IdlType*       attrType_;
 929  IDL_Boolean    delType_;
 930  Declarator*    declarators_;
 931};
 932
 933
 934// Parameter
 935class Parameter : public Decl {
 936public:
 937  Parameter(const char* file, int line, IDL_Boolean mainFile,
 938	    int direction, IdlType* paramType, const char* identifier);
 939  virtual ~Parameter();
 940
 941  const char* kindAsString() const { return "parameter"; }
 942
 943  // Queries
 944  int         direction()  const { return direction_; }
 945				// 0: in, 1: out, 2: inout
 946  IdlType*    paramType()  const { return paramType_; }
 947  const char* identifier() const { return identifier_; }
 948
 949  void accept(AstVisitor& visitor) { visitor.visitParameter(this); }
 950
 951private:
 952  int            direction_;
 953  IdlType*       paramType_;
 954  IDL_Boolean    delType_;
 955  char*          identifier_;
 956};
 957
 958
 959// List of exceptions
 960class RaisesSpec {
 961public:
 962  RaisesSpec(const ScopedName* sn, const char* file, int line);
 963  ~RaisesSpec();
 964
 965  Exception*  exception() const { return exception_; }
 966  RaisesSpec* next()      const { return next_; }
 967
 968  void append(RaisesSpec* rs) {
 969    if (rs) {
 970      last_->next_ = rs;
 971      last_ = rs;
 972    }
 973  }
 974private:
 975  Exception*  exception_;
 976
 977protected:
 978  RaisesSpec* next_;
 979  RaisesSpec* last_;
 980};
 981
 982// List of contexts
 983class ContextSpec {
 984public:
 985  ContextSpec(const char* c, const char* file, int line);
 986  ~ContextSpec();
 987
 988  const char*  context() const { return context_; }
 989  ContextSpec* next()    const { return next_; }
 990
 991  void append(ContextSpec* rs) {
 992    last_->next_ = rs;
 993    last_ = rs;
 994  }
 995
 996private:
 997  char*  context_;
 998
 999protected:
1000  ContextSpec* next_;
1001  ContextSpec* last_;
1002};
1003
1004
1005// Operation
1006class Operation : public Decl, public DeclRepoId {
1007public:
1008  Operation(const char* file, int line, IDL_Boolean mainFile,
1009	    IDL_Boolean oneway, IdlType* return_type,
1010	    const char* identifier);
1011  virtual ~Operation();
1012
1013  const char* kindAsString() const { return "operation"; }
1014
1015  // Queries
1016  IDL_Boolean    oneway()     const { return oneway_; }
1017  IdlType*       returnType() const { return returnType_; }
1018  Parameter*     parameters() const { return parameters_; }
1019  RaisesSpec*    raises()     const { return raises_; }
1020  ContextSpec*   contexts()   const { return contexts_; }
1021
1022  void accept(AstVisitor& visitor) { visitor.visitOperation(this); }
1023
1024  void closeParens();
1025  void finishConstruction(Parameter* parameters, RaisesSpec* raises,
1026			  ContextSpec* contexts);
1027
1028private:
1029  IDL_Boolean    oneway_;
1030  IdlType*       returnType_;
1031  IDL_Boolean    delType_;
1032  Parameter*     parameters_;
1033  RaisesSpec*    raises_;
1034  ContextSpec*   contexts_;
1035};
1036
1037
1038// Native
1039class Native : public Decl, public DeclRepoId {
1040public:
1041  Native(const char* file, int line, IDL_Boolean mainFile,
1042	 const char* identifier);
1043  virtual ~Native();
1044
1045  const char* kindAsString() const { return "native"; }
1046
1047  void accept(AstVisitor& visitor) { visitor.visitNative(this); }
1048};
1049
1050
1051// Things for valuetype
1052
1053class StateMember : public Decl {
1054public:
1055  StateMember(const char* file, int line, IDL_Boolean mainFile,
1056	      int memberAccess, IdlType* memberType,
1057	      IDL_Boolean constrType, Declarator* declarators);
1058  virtual ~StateMember();
1059
1060  const char* kindAsString() const { return "state member"; }
1061
1062  // Queries
1063  int            memberAccess() const { return memberAccess_; }
1064				// 0: public, 1: private
1065  IdlType*       memberType()   const { return memberType_; }
1066  IDL_Boolean    constrType()   const { return constrType_; }
1067  Declarator*    declarators()  const { return declarators_; }
1068
1069  void accept(AstVisitor& visitor) { visitor.visitStateMember(this); }
1070
1071private:
1072  int            memberAccess_;
1073  IdlType*       memberType_;
1074  IDL_Boolean    delType_;
1075  IDL_Boolean    constrType_;
1076  Declarator*    declarators_;
1077};
1078
1079class Factory : public Decl {
1080public:
1081  Factory(const char* file, int line, IDL_Boolean mainFile,
1082	  const char* identifier);
1083  ~Factory();
1084
1085  const char* kindAsString() const { return "initializer"; }
1086
1087  // Queries
1088  const char* identifier() const { return identifier_; }
1089  Parameter*  parameters() const { return parameters_; }
1090  RaisesSpec* raises()     const { return raises_; }
1091
1092  void accept(AstVisitor& visitor) { visitor.visitFactory(this); }
1093
1094  void closeParens();
1095  void finishConstruction(Parameter* parameters, RaisesSpec* raises);
1096
1097private:
1098  char*       identifier_;
1099  Parameter*  parameters_;
1100  RaisesSpec* raises_;
1101};
1102
1103
1104// Base class for all the multifarious value types
1105class ValueBase : public Decl, public DeclRepoId {
1106public:
1107  ValueBase(Decl::Kind k, const char* file, int line, IDL_Boolean mainFile,
1108	    const char* identifier);
1109  virtual ~ValueBase();
1110};
1111
1112
1113// Forward declared value
1114class ValueForward : public ValueBase {
1115public:
1116  ValueForward(const char* file, int line, IDL_Boolean mainFile,
1117	       IDL_Boolean abstract, const char* identifier);
1118  virtual ~ValueForward();
1119
1120  const char* kindAsString() const { return "forward value"; }
1121
1122  // Queries
1123  IDL_Boolean    abstract()   const { return abstract_; }
1124  ValueBase*     definition() const;
1125  IDL_Boolean    isFirst()    const { return !firstForward_; }
1126  IdlType*       thisType()   const { return thisType_; }
1127
1128  void accept(AstVisitor& visitor) { visitor.visitValueForward(this); }
1129
1130  void setDefinition(ValueBase* defn);
1131
1132private:
1133  IDL_Boolean    abstract_;
1134  ValueBase*     definition_;
1135  ValueForward*  firstForward_;
1136  IdlType*       thisType_;
1137};
1138
1139
1140class ValueBox : public ValueBase {
1141public:
1142  ValueBox(const char* file, int line, IDL_Boolean mainFile,
1143	   const char* identifier, IdlType* boxedType,
1144	   IDL_Boolean constrType);
1145  virtual ~ValueBox();
1146
1147  const char* kindAsString() const { return "value box"; }
1148
1149  // Queries
1150  IdlType*       boxedType()  const { return boxedType_; }
1151  IDL_Boolean    constrType() const { return constrType_; }
1152  IdlType*       thisType()   const { return thisType_; }
1153
1154  void accept(AstVisitor& visitor) { visitor.visitValueBox(this); }
1155
1156private:
1157  IdlType*       boxedType_;
1158  IDL_Boolean    constrType_;
1159  IDL_Boolean    delType_;
1160  IdlType*       thisType_;
1161};
1162
1163
1164class ValueInheritSpec {
1165public:
1166  ValueInheritSpec(ScopedName* sn, const char* file, int line);
1167
1168  virtual ~ValueInheritSpec() { if (next_) delete next_; }
1169
1170  ValueBase*        value()       const { return value_; }
1171  Decl*             decl()        const { return decl_; }
1172  const Scope*      scope()       const { return scope_; }
1173  ValueInheritSpec* next()        const { return next_; }
1174  IDL_Boolean       truncatable() const { return truncatable_; }
1175
1176  void append(ValueInheritSpec* is, const char* file, int line);
1177  void setTruncatable() { truncatable_ = 1; }
1178
1179private:
1180  ValueBase*   value_;
1181  Decl*        decl_;
1182  const Scope* scope_;
1183
1184protected:
1185  ValueInheritSpec* next_;
1186  IDL_Boolean       truncatable_;
1187};
1188
1189
1190class ValueInheritSupportSpec {
1191public:
1192  ValueInheritSupportSpec(ValueInheritSpec* inherits,
1193			  InheritSpec*      supports) :
1194    inherits_(inherits), supports_(supports) {}
1195
1196  ~ValueInheritSupportSpec() {}
1197
1198  ValueInheritSpec* inherits() const { return inherits_; }
1199  InheritSpec*      supports() const { return supports_; }
1200
1201private:
1202  ValueInheritSpec* inherits_;
1203  InheritSpec*      supports_;
1204};
1205
1206
1207class ValueAbs : public ValueBase {
1208public:
1209  ValueAbs(const char* file, int line, IDL_Boolean mainFile,
1210	   const char* identifier, ValueInheritSpec* inherits,
1211	   InheritSpec* supports);
1212  virtual ~ValueAbs();
1213
1214  const char* kindAsString() const { return "abstract valuetype"; }
1215
1216  // Queries
1217  ValueInheritSpec* inherits() const { return inherits_; }
1218  InheritSpec*      supports() const { return supports_; }
1219  Decl*             contents() const { return contents_; }
1220  Scope*            scope()    const { return scope_;    }
1221  IdlType*          thisType() const { return thisType_; }
1222
1223  void accept(AstVisitor& visitor) { visitor.visitValueAbs(this); }
1224
1225  void finishConstruction(Decl* contents);
1226
1227private:
1228  ValueInheritSpec* inherits_;
1229  InheritSpec*      supports_;
1230  Decl*             contents_;
1231  Scope*            scope_;
1232  IdlType*          thisType_;
1233};
1234
1235
1236class Value : public ValueBase {
1237public:
1238  Value(const char* file, int line, IDL_Boolean mainFile,
1239	IDL_Boolean custom, const char* identifier,
1240	ValueInheritSpec* inherits, InheritSpec* supports);
1241  virtual ~Value();
1242
1243  const char* kindAsString() const { return "valuetype"; }
1244
1245  // Queries
1246  IDL_Boolean       custom()   const { return custom_; }
1247  ValueInheritSpec* inherits() const { return inherits_; }
1248  InheritSpec*      supports() const { return supports_; }
1249  Decl*             contents() const { return contents_; }
1250  Scope*            scope()    const { return scope_;    }
1251  IdlType*          thisType() const { return thisType_; }
1252
1253  void accept(AstVisitor& visitor) { visitor.visitValue(this); }
1254
1255  void finishConstruction(Decl* contents);
1256
1257private:
1258  IDL_Boolean       custom_;
1259  ValueInheritSpec* inherits_;
1260  InheritSpec*      supports_;
1261  Decl*             contents_;
1262  Scope*            scope_;
1263  IdlType*          thisType_;
1264};
1265
1266
1267#endif // _idlast_h_