1 // 2 // Copyright (c) ZeroC, Inc. All rights reserved. 3 // 4 5 #ifndef SLICE_PARSER_H 6 #define SLICE_PARSER_H 7 8 #include <IceUtil/Shared.h> 9 #include <IceUtil/Handle.h> 10 #include <string> 11 #include <vector> 12 #include <list> 13 #include <stack> 14 #include <map> 15 #include <set> 16 #include <stdio.h> 17 18 namespace Slice 19 { 20 21 #if defined(_WIN32) && !defined(__MINGW32__) 22 23 const IceUtil::Int64 Int32Max = 0x7fffffffi64; 24 const IceUtil::Int64 Int32Min = -Int32Max - 1i64; 25 26 #else 27 28 # if defined(INT32_MIN) && defined(INT32_MAX) 29 30 const IceUtil::Int64 Int32Max = INT32_MAX; 31 const IceUtil::Int64 Int32Min = INT32_MIN; 32 33 # else 34 35 const IceUtil::Int64 Int32Max = 0x7fffffffLL; 36 const IceUtil::Int64 Int32Min = -Int32Max - 1LL; 37 38 # endif 39 40 #endif 41 42 const IceUtil::Int64 Int16Max = 0x7fff; 43 const IceUtil::Int64 Int16Min = -Int16Max - 1; 44 const IceUtil::Int64 ByteMax = 0xff; 45 const IceUtil::Int64 ByteMin = 0x00; 46 47 enum NodeType 48 { 49 Dummy, 50 Real 51 }; 52 53 // 54 // Format preference for classes and exceptions. 55 // 56 enum FormatType 57 { 58 DefaultFormat, // No preference was specified. 59 CompactFormat, // Minimal format. 60 SlicedFormat // Full format. 61 }; 62 63 enum WarningCategory 64 { 65 All, 66 Deprecated, 67 InvalidMetaData 68 }; 69 70 class GrammarBase; 71 class SyntaxTreeBase; 72 class Type; 73 class Builtin; 74 class Contained; 75 class Container; 76 class Module; 77 class Constructed; 78 class ClassDecl; 79 class ClassDef; 80 class Proxy; 81 class Exception; 82 class Struct; 83 class Operation; 84 class ParamDecl; 85 class DataMember; 86 class Sequence; 87 class Dictionary; 88 class Enum; 89 class Enumerator; 90 class Const; 91 class Unit; 92 class CICompare; 93 class DerivedToBaseCompare; 94 class ModulePartialCompare; 95 96 typedef ::IceUtil::Handle<GrammarBase> GrammarBasePtr; 97 typedef ::IceUtil::Handle<SyntaxTreeBase> SyntaxTreeBasePtr; 98 typedef ::IceUtil::Handle<Type> TypePtr; 99 typedef ::IceUtil::Handle<Builtin> BuiltinPtr; 100 typedef ::IceUtil::Handle<Contained> ContainedPtr; 101 typedef ::IceUtil::Handle<Container> ContainerPtr; 102 typedef ::IceUtil::Handle<Module> ModulePtr; 103 typedef ::IceUtil::Handle<Constructed> ConstructedPtr; 104 typedef ::IceUtil::Handle<ClassDecl> ClassDeclPtr; 105 typedef ::IceUtil::Handle<ClassDef> ClassDefPtr; 106 typedef ::IceUtil::Handle<Proxy> ProxyPtr; 107 typedef ::IceUtil::Handle<Exception> ExceptionPtr; 108 typedef ::IceUtil::Handle<Struct> StructPtr; 109 typedef ::IceUtil::Handle<Operation> OperationPtr; 110 typedef ::IceUtil::Handle<ParamDecl> ParamDeclPtr; 111 typedef ::IceUtil::Handle<DataMember> DataMemberPtr; 112 typedef ::IceUtil::Handle<Sequence> SequencePtr; 113 typedef ::IceUtil::Handle<Dictionary> DictionaryPtr; 114 typedef ::IceUtil::Handle<Enum> EnumPtr; 115 typedef ::IceUtil::Handle<Enumerator> EnumeratorPtr; 116 typedef ::IceUtil::Handle<Const> ConstPtr; 117 typedef ::IceUtil::Handle<Unit> UnitPtr; 118 119 typedef std::list<TypePtr> TypeList; 120 typedef std::list<ExceptionPtr> ExceptionList; 121 typedef std::set<std::string> StringSet; 122 typedef std::list<std::string> StringList; 123 typedef std::pair<TypePtr, std::string> TypeString; 124 typedef std::list<TypeString> TypeStringList; 125 typedef std::list<ContainedPtr> ContainedList; 126 typedef std::list<ModulePtr> ModuleList; 127 typedef std::list<ConstructedPtr> ConstructedList; 128 typedef std::list<ClassDefPtr> ClassList; 129 typedef std::list<ExceptionPtr> ExceptionList; 130 typedef std::list<StructPtr> StructList; 131 typedef std::list<SequencePtr> SequenceList; 132 typedef std::list<DictionaryPtr> DictionaryList; 133 typedef std::list<EnumPtr> EnumList; 134 typedef std::list<ConstPtr> ConstList; 135 typedef std::list<OperationPtr> OperationList; 136 typedef std::list<DataMemberPtr> DataMemberList; 137 typedef std::list<ParamDeclPtr> ParamDeclList; 138 typedef std::list<EnumeratorPtr> EnumeratorList; 139 140 struct ConstDef 141 { 142 TypePtr type; 143 SyntaxTreeBasePtr value; 144 std::string valueAsString; 145 std::string valueAsLiteral; 146 }; 147 148 struct OptionalDef 149 { 150 TypePtr type; 151 std::string name; 152 bool optional; 153 int tag; 154 }; 155 156 // ---------------------------------------------------------------------- 157 // CICompare -- function object to do case-insensitive string comparison. 158 // ---------------------------------------------------------------------- 159 160 class CICompare : public std::binary_function<std::string, std::string, bool> 161 { 162 public: 163 164 bool operator()(const std::string&, const std::string&) const; 165 }; 166 167 #if defined(__SUNPRO_CC) 168 bool cICompare(const std::string&, const std::string&); 169 #endif 170 171 // ---------------------------------------------------------------------- 172 // DerivedToBaseCompare -- function object to do sort exceptions into 173 // most-derived to least-derived order. 174 // ---------------------------------------------------------------------- 175 176 class DerivedToBaseCompare : public std::binary_function<std::string, std::string, bool> 177 { 178 public: 179 180 bool operator()(const ExceptionPtr&, const ExceptionPtr&) const; 181 }; 182 183 #if defined(__SUNPRO_CC) 184 bool derivedToBaseCompare(const ExceptionPtr&, const ExceptionPtr&); 185 #endif 186 187 // ---------------------------------------------------------------------- 188 // ParserVisitor 189 // ---------------------------------------------------------------------- 190 191 class ParserVisitor 192 { 193 public: 194 ~ParserVisitor()195 virtual ~ParserVisitor() { } visitUnitStart(const UnitPtr &)196 virtual bool visitUnitStart(const UnitPtr&) { return true; } visitUnitEnd(const UnitPtr &)197 virtual void visitUnitEnd(const UnitPtr&) { } visitModuleStart(const ModulePtr &)198 virtual bool visitModuleStart(const ModulePtr&) { return true; } visitModuleEnd(const ModulePtr &)199 virtual void visitModuleEnd(const ModulePtr&) { } visitClassDecl(const ClassDeclPtr &)200 virtual void visitClassDecl(const ClassDeclPtr&) { } visitClassDefStart(const ClassDefPtr &)201 virtual bool visitClassDefStart(const ClassDefPtr&) { return true; } visitClassDefEnd(const ClassDefPtr &)202 virtual void visitClassDefEnd(const ClassDefPtr&) { } visitExceptionStart(const ExceptionPtr &)203 virtual bool visitExceptionStart(const ExceptionPtr&) { return true; } visitExceptionEnd(const ExceptionPtr &)204 virtual void visitExceptionEnd(const ExceptionPtr&) { } visitStructStart(const StructPtr &)205 virtual bool visitStructStart(const StructPtr&) { return true; } visitStructEnd(const StructPtr &)206 virtual void visitStructEnd(const StructPtr&) { } visitOperation(const OperationPtr &)207 virtual void visitOperation(const OperationPtr&) { } visitParamDecl(const ParamDeclPtr &)208 virtual void visitParamDecl(const ParamDeclPtr&) { } visitDataMember(const DataMemberPtr &)209 virtual void visitDataMember(const DataMemberPtr&) { } visitSequence(const SequencePtr &)210 virtual void visitSequence(const SequencePtr&) { } visitDictionary(const DictionaryPtr &)211 virtual void visitDictionary(const DictionaryPtr&) { } visitEnum(const EnumPtr &)212 virtual void visitEnum(const EnumPtr&) { } visitConst(const ConstPtr &)213 virtual void visitConst(const ConstPtr&) { } 214 }; 215 216 // ---------------------------------------------------------------------- 217 // DefinitionContext 218 // ---------------------------------------------------------------------- 219 220 class DefinitionContext : public ::IceUtil::SimpleShared 221 { 222 public: 223 224 DefinitionContext(int, const StringList&); 225 226 std::string filename() const; 227 int includeLevel() const; 228 bool seenDefinition() const; 229 230 void setFilename(const std::string&); 231 void setSeenDefinition(); 232 233 bool hasMetaData() const; 234 void setMetaData(const StringList&); 235 std::string findMetaData(const std::string&) const; 236 StringList getMetaData() const; 237 238 // 239 // Emit warning unless filtered out by [["suppress-warning"]] 240 // 241 void warning(WarningCategory, const std::string&, int, const std::string&) const; 242 void warning(WarningCategory, const std::string&, const std::string&, const std::string&) const; 243 244 private: 245 246 bool suppressWarning(WarningCategory) const; 247 void initSuppressedWarnings(); 248 249 int _includeLevel; 250 StringList _metaData; 251 std::string _filename; 252 bool _seenDefinition; 253 std::set<WarningCategory> _suppressedWarnings; 254 }; 255 typedef ::IceUtil::Handle<DefinitionContext> DefinitionContextPtr; 256 257 // ---------------------------------------------------------------------- 258 // Comment 259 // ---------------------------------------------------------------------- 260 261 class Comment : public ::IceUtil::SimpleShared 262 { 263 public: 264 265 bool isDeprecated() const; 266 StringList deprecated() const; 267 268 StringList overview() const; // Contains all introductory lines up to the first tag. 269 StringList misc() const; // Contains unrecognized tags. 270 StringList seeAlso() const; // Targets of @see tags. 271 272 StringList returns() const; // Description of an operation's return value. 273 std::map<std::string, StringList> parameters() const; // Parameter descriptions for an op. Key is parameter name. 274 std::map<std::string, StringList> exceptions() const; // Exception descriptions for an op. Key is exception name. 275 276 private: 277 278 Comment(); 279 280 bool _isDeprecated; 281 StringList _deprecated; 282 StringList _overview; 283 StringList _misc; 284 StringList _seeAlso; 285 286 StringList _returns; 287 std::map<std::string, StringList> _parameters; 288 std::map<std::string, StringList> _exceptions; 289 290 friend class Contained; 291 }; 292 typedef ::IceUtil::Handle<Comment> CommentPtr; 293 294 // ---------------------------------------------------------------------- 295 // GrammarBase 296 // ---------------------------------------------------------------------- 297 298 class GrammarBase : public ::IceUtil::SimpleShared 299 { 300 }; 301 302 // ---------------------------------------------------------------------- 303 // SyntaxTreeBase 304 // ---------------------------------------------------------------------- 305 306 class SyntaxTreeBase : public GrammarBase 307 { 308 public: 309 310 virtual void destroy(); 311 UnitPtr unit() const; 312 DefinitionContextPtr definitionContext() const; // May be nil 313 virtual void visit(ParserVisitor*, bool); 314 315 protected: 316 317 SyntaxTreeBase(const UnitPtr&, const DefinitionContextPtr& = 0); 318 319 UnitPtr _unit; 320 DefinitionContextPtr _definitionContext; 321 }; 322 323 // ---------------------------------------------------------------------- 324 // Type 325 // ---------------------------------------------------------------------- 326 327 class Type : public virtual SyntaxTreeBase 328 { 329 public: 330 331 virtual bool isLocal() const = 0; 332 virtual std::string typeId() const = 0; 333 virtual bool usesClasses() const = 0; 334 virtual size_t minWireSize() const = 0; 335 virtual bool isVariableLength() const = 0; 336 337 protected: 338 339 Type(const UnitPtr&); 340 }; 341 342 // ---------------------------------------------------------------------- 343 // Builtin 344 // ---------------------------------------------------------------------- 345 346 class Builtin : public virtual Type 347 { 348 public: 349 350 enum Kind 351 { 352 KindByte, 353 KindBool, 354 KindShort, 355 KindInt, 356 KindLong, 357 KindFloat, 358 KindDouble, 359 KindString, 360 KindObject, 361 KindObjectProxy, 362 KindLocalObject, 363 KindValue 364 }; 365 366 virtual bool isLocal() const; 367 virtual std::string typeId() const; 368 virtual bool usesClasses() const; 369 virtual size_t minWireSize() const; 370 virtual bool isVariableLength() const; 371 372 Kind kind() const; 373 std::string kindAsString() const; 374 375 static const char* builtinTable[]; 376 377 protected: 378 379 Builtin(const UnitPtr&, Kind); 380 friend class Unit; 381 382 Kind _kind; 383 }; 384 385 // ---------------------------------------------------------------------- 386 // Contained 387 // ---------------------------------------------------------------------- 388 389 class Contained : public virtual SyntaxTreeBase 390 { 391 public: 392 393 ContainerPtr container() const; 394 std::string name() const; 395 std::string scoped() const; 396 std::string scope() const; 397 std::string flattenedScope() const; 398 std::string file() const; 399 std::string line() const; 400 std::string comment() const; 401 CommentPtr parseComment(bool) const; 402 403 int includeLevel() const; 404 void updateIncludeLevel(); 405 406 bool hasMetaData(const std::string&) const; 407 bool findMetaData(const std::string&, std::string&) const; 408 std::list<std::string> getMetaData() const; 409 void setMetaData(const std::list<std::string>&); 410 void addMetaData(const std::string&); // TODO: remove this method once "cs:" and "vb:" are hard errors. 411 412 static FormatType parseFormatMetaData(const std::list<std::string>&); 413 414 enum ContainedType 415 { 416 ContainedTypeSequence, 417 ContainedTypeDictionary, 418 ContainedTypeEnum, 419 ContainedTypeEnumerator, 420 ContainedTypeModule, 421 ContainedTypeClass, 422 ContainedTypeException, 423 ContainedTypeStruct, 424 ContainedTypeOperation, 425 ContainedTypeParamDecl, 426 ContainedTypeDataMember, 427 ContainedTypeConstant 428 }; 429 virtual ContainedType containedType() const = 0; 430 431 virtual bool uses(const ContainedPtr&) const = 0; 432 virtual std::string kindOf() const = 0; 433 434 bool operator<(const Contained&) const; 435 bool operator==(const Contained&) const; 436 437 protected: 438 439 Contained(const ContainerPtr&, const std::string&); 440 friend class Container; 441 442 ContainerPtr _container; 443 std::string _name; 444 std::string _scoped; 445 std::string _file; 446 std::string _line; 447 std::string _comment; 448 int _includeLevel; 449 std::list<std::string> _metaData; 450 }; 451 452 // ---------------------------------------------------------------------- 453 // Container 454 // ---------------------------------------------------------------------- 455 456 class Container : public virtual SyntaxTreeBase 457 { 458 public: 459 460 virtual void destroy(); 461 ModulePtr createModule(const std::string&); 462 ClassDefPtr createClassDef(const std::string&, int, bool, const ClassList&, bool); 463 ClassDeclPtr createClassDecl(const std::string&, bool, bool); 464 ExceptionPtr createException(const std::string&, const ExceptionPtr&, bool, NodeType = Real); 465 StructPtr createStruct(const std::string&, bool, NodeType = Real); 466 SequencePtr createSequence(const std::string&, const TypePtr&, const StringList&, bool, NodeType = Real); 467 DictionaryPtr createDictionary(const std::string&, const TypePtr&, const StringList&, const TypePtr&, 468 const StringList&, bool, NodeType = Real); 469 EnumPtr createEnum(const std::string&, bool, NodeType = Real); 470 EnumeratorPtr createEnumerator(const std::string&); 471 EnumeratorPtr createEnumerator(const std::string&, int); 472 ConstPtr createConst(const std::string, const TypePtr&, const StringList&, const SyntaxTreeBasePtr&, 473 const std::string&, const std::string&, NodeType = Real); 474 TypeList lookupType(const std::string&, bool = true); 475 TypeList lookupTypeNoBuiltin(const std::string&, bool = true, bool = false); 476 ContainedList lookupContained(const std::string&, bool = true); 477 ExceptionPtr lookupException(const std::string&, bool = true); 478 UnitPtr unit() const; 479 ModuleList modules() const; 480 ClassList classes() const; 481 ExceptionList exceptions() const; 482 StructList structs() const; 483 SequenceList sequences() const; 484 DictionaryList dictionaries() const; 485 EnumList enums() const; 486 EnumeratorList enumerators() const; 487 EnumeratorList enumerators(const std::string&) const; 488 ConstList consts() const; 489 ContainedList contents() const; 490 bool hasNonLocalClassDecls() const; 491 bool hasNonLocalClassDefs() const; 492 bool hasLocalClassDefsWithAsync() const; 493 bool hasNonLocalSequences() const; 494 bool hasNonLocalExceptions() const; 495 bool hasStructs() const; 496 bool hasExceptions() const; 497 bool hasDictionaries() const; 498 bool hasOnlyDictionaries(DictionaryList&) const; 499 bool hasClassDecls() const; 500 bool hasClassDefs() const; 501 bool hasLocalClassDefs() const; 502 bool hasNonLocalInterfaceDefs() const; 503 bool hasValueDefs() const; 504 bool hasOnlyClassDecls() const; 505 bool hasOperations() const; // interfaces or classes with operations 506 bool hasNonLocalAbstractClassDefs() const; // interfaces or abstract classes 507 bool hasNonLocalDataOnlyClasses() const; 508 bool hasOtherConstructedOrExceptions() const; // Exceptions or constructed types other than classes. 509 bool hasContentsWithMetaData(const std::string&) const; 510 bool hasAsyncOps() const; 511 bool hasNonLocalContained(Contained::ContainedType) const; 512 std::string thisScope() const; 513 void mergeModules(); 514 void sort(); 515 void sortContents(bool); 516 virtual void visit(ParserVisitor*, bool); 517 void containerRecDependencies(std::set<ConstructedPtr>&); // Internal operation, don't use directly. 518 519 bool checkIntroduced(const std::string&, ContainedPtr = 0); 520 bool nameIsLegal(const std::string&, const char *); 521 bool checkForGlobalDef(const std::string&, const char *); 522 523 protected: 524 525 Container(const UnitPtr&); 526 527 bool checkInterfaceAndLocal(const std::string&, bool, bool, bool, bool, bool); 528 bool checkGlobalMetaData(const StringList&, const StringList&); 529 bool validateConstant(const std::string&, const TypePtr&, SyntaxTreeBasePtr&, const std::string&, bool); 530 EnumeratorPtr validateEnumerator(const std::string&); 531 532 ContainedList _contents; 533 std::map<std::string, ContainedPtr, CICompare> _introducedMap; 534 }; 535 536 // ---------------------------------------------------------------------- 537 // Module 538 // ---------------------------------------------------------------------- 539 540 class Module : public virtual Container, public virtual Contained 541 { 542 public: 543 544 virtual ContainedType containedType() const; 545 virtual bool uses(const ContainedPtr&) const; 546 virtual std::string kindOf() const; 547 virtual void visit(ParserVisitor*, bool); 548 549 protected: 550 551 Module(const ContainerPtr&, const std::string&); 552 friend class Container; 553 }; 554 555 // ---------------------------------------------------------------------- 556 // Constructed 557 // ---------------------------------------------------------------------- 558 559 class Constructed : public virtual Type, public virtual Contained 560 { 561 public: 562 563 virtual bool isLocal() const; 564 virtual std::string typeId() const; 565 virtual bool isVariableLength() const = 0; 566 ConstructedList dependencies(); 567 virtual void recDependencies(std::set<ConstructedPtr>&) = 0; // Internal operation, don't use directly. 568 569 protected: 570 571 Constructed(const ContainerPtr&, const std::string&, bool); 572 573 bool _local; 574 }; 575 576 // ---------------------------------------------------------------------- 577 // ClassDecl 578 // ---------------------------------------------------------------------- 579 580 class ClassDecl : public virtual Constructed 581 { 582 public: 583 584 virtual void destroy(); 585 ClassDefPtr definition() const; 586 bool isInterface() const; 587 virtual ContainedType containedType() const; 588 virtual bool uses(const ContainedPtr&) const; 589 virtual bool usesClasses() const; 590 virtual size_t minWireSize() const; 591 virtual bool isVariableLength() const; 592 virtual void visit(ParserVisitor*, bool); 593 virtual std::string kindOf() const; 594 virtual void recDependencies(std::set<ConstructedPtr>&); // Internal operation, don't use directly. 595 596 static void checkBasesAreLegal(const std::string&, bool, bool, const ClassList&, const UnitPtr&); 597 598 protected: 599 600 ClassDecl(const ContainerPtr&, const std::string&, bool, bool); 601 friend class Container; 602 friend class ClassDef; 603 604 ClassDefPtr _definition; 605 bool _interface; 606 607 private: 608 609 typedef std::list<ClassList> GraphPartitionList; 610 typedef std::list<StringList> StringPartitionList; 611 612 static bool isInList(const GraphPartitionList&, const ClassDefPtr); 613 static void addPartition(GraphPartitionList&, GraphPartitionList::reverse_iterator, const ClassDefPtr); 614 static StringPartitionList toStringPartitionList(const GraphPartitionList&); 615 static void checkPairIntersections(const StringPartitionList&, const std::string&, const UnitPtr&); 616 }; 617 618 // ---------------------------------------------------------------------- 619 // Operation 620 // ---------------------------------------------------------------------- 621 622 class Operation : public virtual Contained, public virtual Container 623 { 624 public: 625 626 // 627 // Note: The order of definitions here *must* match the order of 628 // definitions of ::Ice::OperationMode in slice/Ice/Current.ice! 629 // 630 enum Mode 631 { 632 Normal, 633 Nonmutating, 634 Idempotent 635 }; 636 637 TypePtr returnType() const; 638 bool returnIsOptional() const; 639 int returnTag() const; 640 Mode mode() const; 641 Mode sendMode() const; 642 bool hasMarshaledResult() const; 643 ParamDeclPtr createParamDecl(const std::string&, const TypePtr&, bool, bool, int); 644 ParamDeclList parameters() const; 645 ParamDeclList inParameters() const; 646 void inParameters(ParamDeclList&, ParamDeclList&) const; 647 ParamDeclList outParameters() const; 648 void outParameters(ParamDeclList&, ParamDeclList&) const; 649 ExceptionList throws() const; 650 void setExceptionList(const ExceptionList&); 651 virtual ContainedType containedType() const; 652 virtual bool uses(const ContainedPtr&) const; 653 bool sendsClasses(bool) const; 654 bool returnsClasses(bool) const; 655 bool returnsData() const; 656 bool returnsMultipleValues() const; 657 bool sendsOptionals() const; 658 int attributes() const; 659 FormatType format() const; 660 virtual std::string kindOf() const; 661 virtual void visit(ParserVisitor*, bool); 662 663 protected: 664 665 Operation(const ContainerPtr&, const std::string&, const TypePtr&, bool, int, Mode); 666 friend class ClassDef; 667 668 TypePtr _returnType; 669 bool _returnIsOptional; 670 int _returnTag; 671 ExceptionList _throws; 672 Mode _mode; 673 }; 674 675 // ---------------------------------------------------------------------- 676 // ClassDef 677 // ---------------------------------------------------------------------- 678 679 // 680 // Note: For the purpose of this parser, a class definition is not 681 // considered to be a type, but a class declaration is. And each class 682 // definition has at least one class declaration (but not vice versa), 683 // so if you need the class as a "constructed type", use the 684 // declaration() operation to navigate to the class declaration. 685 // 686 class ClassDef : public virtual Container, public virtual Contained 687 { 688 public: 689 690 virtual void destroy(); 691 OperationPtr createOperation(const std::string&, const TypePtr&, bool, int, Operation::Mode = Operation::Normal); 692 DataMemberPtr createDataMember(const std::string&, const TypePtr&, bool, int, const SyntaxTreeBasePtr&, 693 const std::string&, const std::string&); 694 ClassDeclPtr declaration() const; 695 ClassList bases() const; 696 ClassList allBases() const; 697 OperationList operations() const; 698 OperationList allOperations() const; 699 DataMemberList dataMembers() const; 700 DataMemberList orderedOptionalDataMembers() const; 701 DataMemberList allDataMembers() const; 702 DataMemberList classDataMembers() const; 703 DataMemberList allClassDataMembers() const; 704 bool canBeCyclic() const; 705 bool isAbstract() const; 706 bool isInterface() const; 707 bool isA(const std::string&) const; 708 virtual bool isLocal() const; 709 bool hasDataMembers() const; 710 bool hasOperations() const; 711 bool hasDefaultValues() const; 712 bool inheritsMetaData(const std::string&) const; 713 bool hasBaseDataMembers() const; 714 virtual ContainedType containedType() const; 715 virtual bool uses(const ContainedPtr&) const; 716 virtual std::string kindOf() const; 717 virtual void visit(ParserVisitor*, bool); 718 int compactId() const; 719 bool isDelegate() const; 720 721 protected: 722 723 ClassDef(const ContainerPtr&, const std::string&, int, bool, const ClassList&, bool); 724 friend class Container; 725 726 ClassDeclPtr _declaration; 727 bool _interface; 728 bool _hasDataMembers; 729 bool _hasOperations; 730 ClassList _bases; 731 bool _local; 732 int _compactId; 733 }; 734 735 // ---------------------------------------------------------------------- 736 // Proxy 737 // ---------------------------------------------------------------------- 738 739 class Proxy : public virtual Type 740 { 741 public: 742 743 virtual bool isLocal() const; 744 virtual std::string typeId() const; 745 virtual bool usesClasses() const; 746 virtual size_t minWireSize() const; 747 virtual bool isVariableLength() const; 748 749 ClassDeclPtr _class() const; 750 751 Proxy(const ClassDeclPtr&); 752 753 protected: 754 755 ClassDeclPtr _classDecl; 756 }; 757 758 // ---------------------------------------------------------------------- 759 // Exception 760 // ---------------------------------------------------------------------- 761 762 // No inheritance from Constructed, as this is not a Type 763 class Exception : public virtual Container, public virtual Contained 764 { 765 public: 766 767 virtual void destroy(); 768 DataMemberPtr createDataMember(const std::string&, const TypePtr&, bool, int, const SyntaxTreeBasePtr&, 769 const std::string&, const std::string&); 770 DataMemberList dataMembers() const; 771 DataMemberList orderedOptionalDataMembers() const; 772 DataMemberList allDataMembers() const; 773 DataMemberList classDataMembers() const; 774 DataMemberList allClassDataMembers() const; 775 ExceptionPtr base() const; 776 ExceptionList allBases() const; 777 virtual bool isBaseOf(const ExceptionPtr&) const; 778 virtual bool isLocal() const; 779 virtual ContainedType containedType() const; 780 virtual bool uses(const ContainedPtr&) const; 781 bool usesClasses(bool) const; 782 bool hasDefaultValues() const; 783 bool inheritsMetaData(const std::string&) const; 784 bool hasBaseDataMembers() const; 785 virtual std::string kindOf() const; 786 virtual void visit(ParserVisitor*, bool); 787 788 protected: 789 790 Exception(const ContainerPtr&, const std::string&, const ExceptionPtr&, bool); 791 friend class Container; 792 793 ExceptionPtr _base; 794 bool _local; 795 }; 796 797 // ---------------------------------------------------------------------- 798 // Struct 799 // ---------------------------------------------------------------------- 800 801 class Struct : public virtual Container, public virtual Constructed 802 { 803 public: 804 805 DataMemberPtr createDataMember(const std::string&, const TypePtr&, bool, int, const SyntaxTreeBasePtr&, 806 const std::string&, const std::string&); 807 DataMemberList dataMembers() const; 808 DataMemberList classDataMembers() const; 809 virtual ContainedType containedType() const; 810 virtual bool uses(const ContainedPtr&) const; 811 virtual bool usesClasses() const; 812 virtual size_t minWireSize() const; 813 virtual bool isVariableLength() const; 814 bool hasDefaultValues() const; 815 virtual std::string kindOf() const; 816 virtual void visit(ParserVisitor*, bool); 817 virtual void recDependencies(std::set<ConstructedPtr>&); // Internal operation, don't use directly. 818 819 protected: 820 821 Struct(const ContainerPtr&, const std::string&, bool); 822 friend class Container; 823 }; 824 825 // ---------------------------------------------------------------------- 826 // Sequence 827 // ---------------------------------------------------------------------- 828 829 class Sequence : public virtual Constructed 830 { 831 public: 832 833 TypePtr type() const; 834 StringList typeMetaData() const; 835 virtual ContainedType containedType() const; 836 virtual bool uses(const ContainedPtr&) const; 837 virtual bool usesClasses() const; 838 virtual size_t minWireSize() const; 839 virtual bool isVariableLength() const; 840 virtual std::string kindOf() const; 841 virtual void visit(ParserVisitor*, bool); 842 virtual void recDependencies(std::set<ConstructedPtr>&); // Internal operation, don't use directly. 843 844 protected: 845 846 Sequence(const ContainerPtr&, const std::string&, const TypePtr&, const StringList&, bool); 847 friend class Container; 848 849 TypePtr _type; 850 StringList _typeMetaData; 851 }; 852 853 // ---------------------------------------------------------------------- 854 // Dictionary 855 // ---------------------------------------------------------------------- 856 857 class Dictionary : public virtual Constructed 858 { 859 public: 860 861 TypePtr keyType() const; 862 TypePtr valueType() const; 863 StringList keyMetaData() const; 864 StringList valueMetaData() const; 865 virtual ContainedType containedType() const; 866 virtual bool uses(const ContainedPtr&) const; 867 virtual bool usesClasses() const; 868 virtual size_t minWireSize() const; 869 virtual bool isVariableLength() const; 870 virtual std::string kindOf() const; 871 virtual void visit(ParserVisitor*, bool); 872 virtual void recDependencies(std::set<ConstructedPtr>&); // Internal operation, don't use directly. 873 874 static bool legalKeyType(const TypePtr&, bool&); 875 876 protected: 877 878 Dictionary(const ContainerPtr&, const std::string&, const TypePtr&, const StringList&, const TypePtr&, 879 const StringList&, bool); 880 friend class Container; 881 882 TypePtr _keyType; 883 TypePtr _valueType; 884 StringList _keyMetaData; 885 StringList _valueMetaData; 886 }; 887 888 // ---------------------------------------------------------------------- 889 // Enum 890 // ---------------------------------------------------------------------- 891 892 class Enum : public virtual Container, public virtual Constructed 893 { 894 public: 895 896 virtual void destroy(); 897 bool explicitValue() const; 898 int minValue() const; 899 int maxValue() const; 900 virtual ContainedType containedType() const; 901 virtual bool uses(const ContainedPtr&) const; 902 virtual bool usesClasses() const; 903 virtual size_t minWireSize() const; 904 virtual bool isVariableLength() const; 905 virtual std::string kindOf() const; 906 virtual void visit(ParserVisitor*, bool); 907 virtual void recDependencies(std::set<ConstructedPtr>&); // Internal operation, don't use directly. 908 909 protected: 910 911 Enum(const ContainerPtr&, const std::string&, bool); 912 int newEnumerator(const EnumeratorPtr&); 913 914 friend class Container; 915 friend class Enumerator; 916 917 bool _explicitValue; 918 IceUtil::Int64 _minValue; 919 IceUtil::Int64 _maxValue; 920 int _lastValue; 921 }; 922 923 // ---------------------------------------------------------------------- 924 // Enumerator 925 // ---------------------------------------------------------------------- 926 927 class Enumerator : public virtual Contained 928 { 929 public: 930 931 EnumPtr type() const; 932 virtual bool uses(const ContainedPtr&) const; 933 virtual ContainedType containedType() const; 934 virtual std::string kindOf() const; 935 936 bool explicitValue() const; 937 int value() const; 938 939 protected: 940 941 Enumerator(const ContainerPtr&, const std::string&); 942 Enumerator(const ContainerPtr&, const std::string&, int); 943 friend class Container; 944 945 bool _explicitValue; 946 int _value; 947 }; 948 949 // ---------------------------------------------------------------------- 950 // Const 951 // ---------------------------------------------------------------------- 952 953 class Const : public virtual Contained 954 { 955 public: 956 957 TypePtr type() const; 958 StringList typeMetaData() const; 959 SyntaxTreeBasePtr valueType() const; 960 std::string value() const; 961 std::string literal() const; 962 virtual bool uses(const ContainedPtr&) const; 963 virtual ContainedType containedType() const; 964 virtual std::string kindOf() const; 965 virtual void visit(ParserVisitor*, bool); 966 967 protected: 968 969 Const(const ContainerPtr&, const std::string&, const TypePtr&, const StringList&, const SyntaxTreeBasePtr&, 970 const std::string&, const std::string&); 971 friend class Container; 972 973 TypePtr _type; 974 StringList _typeMetaData; 975 SyntaxTreeBasePtr _valueType; 976 std::string _value; 977 std::string _literal; 978 }; 979 980 // ---------------------------------------------------------------------- 981 // ParamDecl 982 // ---------------------------------------------------------------------- 983 984 class ParamDecl : public virtual Contained 985 { 986 public: 987 988 TypePtr type() const; 989 bool isOutParam() const; 990 bool optional() const; 991 int tag() const; 992 virtual ContainedType containedType() const; 993 virtual bool uses(const ContainedPtr&) const; 994 virtual std::string kindOf() const; 995 virtual void visit(ParserVisitor*, bool); 996 997 protected: 998 999 ParamDecl(const ContainerPtr&, const std::string&, const TypePtr&, bool, bool, int); 1000 friend class Operation; 1001 1002 TypePtr _type; 1003 bool _isOutParam; 1004 bool _optional; 1005 int _tag; 1006 }; 1007 1008 // ---------------------------------------------------------------------- 1009 // DataMember 1010 // ---------------------------------------------------------------------- 1011 1012 class DataMember : public virtual Contained 1013 { 1014 public: 1015 1016 TypePtr type() const; 1017 bool optional() const; 1018 int tag() const; 1019 std::string defaultValue() const; 1020 std::string defaultLiteral() const; 1021 SyntaxTreeBasePtr defaultValueType() const; 1022 virtual ContainedType containedType() const; 1023 virtual bool uses(const ContainedPtr&) const; 1024 virtual std::string kindOf() const; 1025 virtual void visit(ParserVisitor*, bool); 1026 1027 protected: 1028 1029 DataMember(const ContainerPtr&, const std::string&, const TypePtr&, bool, int, const SyntaxTreeBasePtr&, 1030 const std::string&, const std::string&); 1031 friend class ClassDef; 1032 friend class Struct; 1033 friend class Exception; 1034 1035 TypePtr _type; 1036 bool _optional; 1037 int _tag; 1038 SyntaxTreeBasePtr _defaultValueType; 1039 std::string _defaultValue; 1040 std::string _defaultLiteral; 1041 }; 1042 1043 // ---------------------------------------------------------------------- 1044 // Unit 1045 // ---------------------------------------------------------------------- 1046 1047 class Unit : public virtual Container 1048 { 1049 public: 1050 1051 static UnitPtr createUnit(bool, bool, bool, bool, const StringList& = StringList()); 1052 1053 bool ignRedefs() const; 1054 bool allowIcePrefix() const; 1055 bool allowUnderscore() const; 1056 1057 void setComment(const std::string&); 1058 std::string currentComment(); // Not const, as this function removes the current comment. 1059 std::string currentFile() const; 1060 std::string topLevelFile() const; 1061 int currentLine() const; 1062 1063 void nextLine(); 1064 bool scanPosition(const char*); 1065 int currentIncludeLevel() const; 1066 1067 void addGlobalMetaData(const StringList&); 1068 1069 void setSeenDefinition(); 1070 1071 void error(const std::string&); // Not const because error count is increased 1072 void warning(WarningCategory, const std::string&) const; 1073 1074 ContainerPtr currentContainer() const; 1075 void pushContainer(const ContainerPtr&); 1076 void popContainer(); 1077 1078 DefinitionContextPtr currentDefinitionContext() const; 1079 void pushDefinitionContext(); 1080 void popDefinitionContext(); 1081 DefinitionContextPtr findDefinitionContext(const std::string&) const; 1082 1083 void addContent(const ContainedPtr&); 1084 void removeContent(const ContainedPtr&); 1085 ContainedList findContents(const std::string&) const; 1086 ClassList findDerivedClasses(const ClassDefPtr&) const; 1087 ExceptionList findDerivedExceptions(const ExceptionPtr&) const; 1088 ContainedList findUsedBy(const ContainedPtr&) const; 1089 1090 void addTypeId(int, const std::string&); 1091 std::string getTypeId(int) const; 1092 bool hasCompactTypeId() const; 1093 1094 bool usesNonLocals() const; 1095 bool usesConsts() const; 1096 1097 // 1098 // Returns the path names of the files included directly by the top-level file. 1099 // 1100 StringList includeFiles() const; 1101 1102 // 1103 // Returns the path names of all files parsed by this unit. 1104 // 1105 StringList allFiles() const; 1106 1107 int parse(const std::string&, FILE*, bool); 1108 1109 virtual void destroy(); 1110 virtual void visit(ParserVisitor*, bool); 1111 1112 BuiltinPtr builtin(Builtin::Kind); // Not const, as builtins are created on the fly. (Lazy initialization.) 1113 1114 void addTopLevelModule(const std::string&, const std::string&); 1115 std::set<std::string> getTopLevelModules(const std::string&) const; 1116 1117 private: 1118 1119 Unit(bool, bool, bool, bool, const StringList&); 1120 static void eraseWhiteSpace(::std::string&); 1121 bool checkUndefinedTypes(); 1122 1123 bool _ignRedefs; 1124 bool _all; 1125 bool _allowIcePrefix; 1126 bool _allowUnderscore; 1127 StringList _defaultGlobalMetaData; 1128 int _errors; 1129 std::string _currentComment; 1130 int _currentLine; 1131 int _currentIncludeLevel; 1132 std::string _currentFile; 1133 std::string _topLevelFile; 1134 std::stack<DefinitionContextPtr> _definitionContextStack; 1135 StringList _includeFiles; 1136 std::stack<ContainerPtr> _containerStack; 1137 std::map<Builtin::Kind, BuiltinPtr> _builtins; 1138 std::map<std::string, ContainedList> _contentMap; 1139 std::map<std::string, DefinitionContextPtr> _definitionContextMap; 1140 std::map<int, std::string> _typeIds; 1141 std::map< std::string, std::set<std::string> > _fileTopLevelModules; 1142 }; 1143 1144 extern Unit* unit; // The current parser for bison/flex 1145 1146 } 1147 1148 #endif 1149