1//===- AttributeSet.cpp ---------------------------------------------------===// 2// 3// The MCLinker Project 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9#include <mcld/MC/Attribute.h> 10#include <mcld/MC/AttributeSet.h> 11#include <cstddef> 12 13using namespace mcld; 14 15//===----------------------------------------------------------------------===// 16// AttributeSet 17//===----------------------------------------------------------------------===// 18AttributeSet::AttributeSet(unsigned int pNum, const Attribute& pPredefined) 19 : m_AttrSet(), m_Predefined(pPredefined) { 20 m_AttrSet.reserve(pNum); 21} 22 23AttributeSet::~AttributeSet() 24{ 25 iterator cur = m_AttrSet.begin(); 26 iterator aEnd = m_AttrSet.end(); 27 28 while(cur != aEnd) { 29 delete (*cur); 30 ++cur; 31 } 32} 33 34Attribute* AttributeSet::exists(const Attribute& pAttr) const 35{ 36 if (m_Predefined == pAttr) 37 return const_cast<Attribute*>(&m_Predefined); 38 39 const_iterator cur = m_AttrSet.begin(); 40 const_iterator aEnd = m_AttrSet.end(); 41 while(cur != aEnd) { 42 if (*(*cur) == pAttr) { 43 return *cur; 44 } 45 ++cur; 46 } 47 return NULL; 48} 49 50void AttributeSet::record(mcld::Attribute &pAttr) 51{ 52 m_AttrSet.push_back(&pAttr); 53} 54 55