00001 //===-- ast/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. 00011 // 00012 // Every declaration associated with a homonym has a visibility attribuite. We 00013 // have: 00014 // 00015 // - immediate visibility -- lexically scoped declarations such as function 00016 // formal parameters, object declarations, etc. 00017 // 00018 // - import visibility -- declarations which are introduced into a scope by 00019 // way of a 'import' clause. 00020 // 00021 //===----------------------------------------------------------------------===// 00022 00023 #ifndef COMMA_AST_HOMONYM_HDR_GUARD 00024 #define COMMA_AST_HOMONYM_HDR_GUARD 00025 00026 #include "comma/ast/AstBase.h" 00027 #include "llvm/ADT/PointerIntPair.h" 00028 #include <list> 00029 00030 namespace comma { 00031 00032 class Homonym { 00033 00034 typedef std::list<Decl*> DeclList; 00035 00036 DeclList directDecls; 00037 DeclList importDecls; 00038 00039 public: 00040 Homonym() { } 00041 00042 ~Homonym() { clear(); } 00043 00044 void clear() { 00045 directDecls.clear(); 00046 importDecls.clear(); 00047 } 00048 00049 void addDirectDecl(Decl *decl) { 00050 directDecls.push_front(decl); 00051 } 00052 00053 void addImportDecl(Decl *decl) { 00054 importDecls.push_front(decl); 00055 } 00056 00057 // Returns true if this Homonym is empty. 00058 bool empty() const { 00059 return directDecls.empty() && importDecls.empty(); 00060 } 00061 00062 // Returns true if this Homonym contains import declarations. 00063 bool hasImportDecls() const { 00064 return !importDecls.empty(); 00065 } 00066 00067 // Returns true if this Homonym contains direct declarations. 00068 bool hasDirectDecls() const { 00069 return !directDecls.empty(); 00070 } 00071 00072 typedef DeclList::iterator DirectIterator; 00073 typedef DeclList::iterator ImportIterator; 00074 00075 DirectIterator beginDirectDecls() { return directDecls.begin(); } 00076 00077 DirectIterator endDirectDecls() { return directDecls.end(); } 00078 00079 ImportIterator beginImportDecls() { return importDecls.begin(); } 00080 00081 ImportIterator endImportDecls() { return importDecls.end(); } 00082 00083 void eraseDirectDecl(DirectIterator &iter) { directDecls.erase(iter); } 00084 00085 void eraseImportDecl(ImportIterator &iter) { importDecls.erase(iter); } 00086 }; 00087 00088 } // End comma namespace. 00089 00090 #endif