00001 //===-- typecheck/Homonym.h ----------------------------------- -*- C++ -*-===// 00002 // 00003 // This file is distributed under the MIT license. See LICENSE.txt for details. 00004 // 00005 // Copyright (C) 2009, Stephen Wilson 00006 // 00007 //===----------------------------------------------------------------------===// 00008 // 00009 // A Homonym represents a set of directly visible declarations associated with a 00010 // given identifier. These objects are used to implement lookup resolution by 00011 // the Scope class. 00012 // 00013 // Every declaration associated with a homonym has a visibility attribuite. We 00014 // have: 00015 // 00016 // - immediate visibility -- lexically scoped declarations such as function 00017 // formal parameters, object declarations, etc. 00018 // 00019 // - import visibility -- declarations which are introduced into a scope by 00020 // way of a 'import' clause. 00021 // 00022 //===----------------------------------------------------------------------===// 00023 00024 #ifndef COMMA_AST_HOMONYM_HDR_GUARD 00025 #define COMMA_AST_HOMONYM_HDR_GUARD 00026 00027 #include "comma/ast/AstBase.h" 00028 #include "llvm/ADT/PointerIntPair.h" 00029 #include <list> 00030 00031 namespace comma { 00032 00033 class Homonym { 00034 00035 typedef std::list<Decl*> DeclList; 00036 00037 DeclList directDecls; 00038 DeclList importDecls; 00039 00040 public: 00041 Homonym() { } 00042 00043 ~Homonym() { clear(); } 00044 00045 void clear() { 00046 directDecls.clear(); 00047 importDecls.clear(); 00048 } 00049 00050 void addDirectDecl(Decl *decl) { 00051 directDecls.push_front(decl); 00052 } 00053 00054 void addImportDecl(Decl *decl) { 00055 importDecls.push_front(decl); 00056 } 00057 00058 // Returns true if this Homonym is empty. 00059 bool empty() const { 00060 return directDecls.empty() && importDecls.empty(); 00061 } 00062 00063 // Returns true if this Homonym contains import declarations. 00064 bool hasImportDecls() const { 00065 return !importDecls.empty(); 00066 } 00067 00068 // Returns true if this Homonym contains direct declarations. 00069 bool hasDirectDecls() const { 00070 return !directDecls.empty(); 00071 } 00072 00073 typedef DeclList::iterator DirectIterator; 00074 typedef DeclList::iterator ImportIterator; 00075 00076 DirectIterator beginDirectDecls() { return directDecls.begin(); } 00077 00078 DirectIterator endDirectDecls() { return directDecls.end(); } 00079 00080 ImportIterator beginImportDecls() { return importDecls.begin(); } 00081 00082 ImportIterator endImportDecls() { return importDecls.end(); } 00083 00084 void eraseDirectDecl(DirectIterator &iter) { directDecls.erase(iter); } 00085 00086 void eraseImportDecl(ImportIterator &iter) { importDecls.erase(iter); } 00087 }; 00088 00089 } // End comma namespace. 00090 00091 #endif