00001 //===-- ast/SignatureSet.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 // The following class provides a container for the set of signatures associated 00010 // with a particular model. Note that is class is not a member of the Ast 00011 // hierarchy. 00012 // 00013 // SignatureSet's are populated by specifying the direct signatures (those 00014 // signatures which are explicitly named in the declaration of the associated 00015 // model). Recursively, the SignatureSet's associated with the direct 00016 // signatures are then consulted to obtain the set of indirect signatures. 00017 // 00018 //===----------------------------------------------------------------------===// 00019 00020 #ifndef COMMA_AST_SIGNATURESET_HDR_GUARD 00021 #define COMMA_AST_SIGNATURESET_HDR_GUARD 00022 00023 #include "comma/ast/AstBase.h" 00024 00025 #include "llvm/ADT/SetVector.h" 00026 00027 namespace comma { 00028 00029 class SignatureType; 00030 class Model; 00031 00032 class SignatureSet { 00033 00034 typedef llvm::SetVector<SignatureType*> SignatureTable; 00035 00036 SignatureTable directSignatures; 00037 SignatureTable allSignatures; 00038 00039 ModelDecl *associatedModel; 00040 00041 public: 00042 SignatureSet(ModelDecl *model) 00043 : associatedModel(model) { } 00044 00049 bool addDirectSignature(SignatureType *signature); 00050 00053 bool contains(SignatureType *signature) const { 00054 return allSignatures.count(signature); 00055 } 00056 00059 bool isDirect(SignatureType *signature) const { 00060 return directSignatures.count(signature); 00061 } 00062 00065 bool isIndirect(SignatureType *signature) const { 00066 return contains(signature) && !isDirect(signature); 00067 } 00068 00070 unsigned numSignatures() const { return allSignatures.size(); } 00071 00073 unsigned size() const { return numSignatures(); } 00074 00076 unsigned numDirectSignatures() const { return directSignatures.size(); } 00077 00079 unsigned numIndirectSignatures() const { 00080 return numSignatures() - numDirectSignatures(); 00081 } 00082 00083 // Returns the model which owns this set. 00084 const ModelDecl *getAssociatedModel() const { return associatedModel; } 00085 ModelDecl *getAssociatedModel() { return associatedModel; } 00086 00087 typedef SignatureTable::iterator iterator; 00088 typedef SignatureTable::const_iterator const_iterator; 00089 00094 iterator beginDirect() { return directSignatures.begin(); } 00095 iterator endDirect() { return directSignatures.end(); } 00096 00097 const_iterator beginDirect() const { return directSignatures.begin(); } 00098 const_iterator endDirect() const { return directSignatures.end(); } 00099 00104 iterator begin() { return allSignatures.begin(); } 00105 iterator end() { return allSignatures.end(); } 00106 00107 const_iterator begin() const { return allSignatures.begin(); } 00108 const_iterator end() const { return allSignatures.end(); } 00109 }; 00110 00111 } // End comma namespace 00112 00113 #endif