Scope.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Copyright (c) 2008 Roberto Raggi <[email protected]>
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy
  4. // of this software and associated documentation files (the "Software"), to deal
  5. // in the Software without restriction, including without limitation the rights
  6. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. // copies of the Software, and to permit persons to whom the Software is
  8. // furnished to do so, subject to the following conditions:
  9. //
  10. // The above copyright notice and this permission notice shall be included in
  11. // all copies or substantial portions of the Software.
  12. //
  13. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. // THE SOFTWARE.
  20. #ifndef CPLUSPLUS_SCOPE_H
  21. #define CPLUSPLUS_SCOPE_H
  22. #include "CPlusPlusForwardDeclarations.h"
  23. #include "Symbol.h"
  24. #include "Names.h"
  25. namespace CPlusPlus {
  26. class CPLUSPLUS_EXPORT Scope: public Symbol
  27. {
  28. public:
  29. Scope(TranslationUnit *translationUnit, unsigned sourceLocation, const Name *name);
  30. Scope(Clone *clone, Subst *subst, Scope *original);
  31. virtual ~Scope();
  32. /// Adds a Symbol to this Scope.
  33. void addMember(Symbol *symbol);
  34. /// Returns true if this Scope is empty; otherwise returns false.
  35. bool isEmpty() const;
  36. /// Returns the number of symbols is in the scope.
  37. unsigned memberCount() const;
  38. /// Returns the Symbol at the given position.
  39. Symbol *memberAt(unsigned index) const;
  40. typedef Symbol **iterator;
  41. /// Returns the first Symbol in the scope.
  42. iterator firstMember() const;
  43. /// Returns the last Symbol in the scope.
  44. iterator lastMember() const;
  45. Symbol *find(const Identifier *id) const;
  46. Symbol *find(OperatorNameId::Kind operatorId) const;
  47. /// Set the start offset of the scope
  48. unsigned startOffset() const;
  49. void setStartOffset(unsigned offset);
  50. /// Set the end offset of the scope
  51. unsigned endOffset() const;
  52. void setEndOffset(unsigned offset);
  53. virtual const Scope *asScope() const
  54. { return this; }
  55. virtual Scope *asScope()
  56. { return this; }
  57. private:
  58. SymbolTable *_members;
  59. unsigned _startOffset;
  60. unsigned _endOffset;
  61. };
  62. } // namespace CPlusPlus
  63. #endif // CPLUSPLUS_SCOPE_H