122add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao//===- AttributeSet.cpp ---------------------------------------------------===//
222add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao//
322add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao//                     The MCLinker Project
422add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao//
522add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao// This file is distributed under the University of Illinois Open Source
622add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao// License. See LICENSE.TXT for details.
722add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao//
822add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao//===----------------------------------------------------------------------===//
937b74a387bb3993387029859c2d9d051c41c724eStephen Hines#include "mcld/MC/AttributeSet.h"
1037b74a387bb3993387029859c2d9d051c41c724eStephen Hines
1137b74a387bb3993387029859c2d9d051c41c724eStephen Hines#include "mcld/MC/Attribute.h"
1237b74a387bb3993387029859c2d9d051c41c724eStephen Hines
1322add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao#include <cstddef>
1422add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao
1537b74a387bb3993387029859c2d9d051c41c724eStephen Hinesnamespace mcld {
1622add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao
1722add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao//===----------------------------------------------------------------------===//
1822add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao// AttributeSet
1922add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao//===----------------------------------------------------------------------===//
2022add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei LiaoAttributeSet::AttributeSet(unsigned int pNum, const Attribute& pPredefined)
2137b74a387bb3993387029859c2d9d051c41c724eStephen Hines    : m_AttrSet(), m_Predefined(pPredefined) {
2222add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao  m_AttrSet.reserve(pNum);
2322add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao}
2422add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao
2537b74a387bb3993387029859c2d9d051c41c724eStephen HinesAttributeSet::~AttributeSet() {
2622add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao  iterator cur = m_AttrSet.begin();
2722add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao  iterator aEnd = m_AttrSet.end();
2822add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao
2937b74a387bb3993387029859c2d9d051c41c724eStephen Hines  while (cur != aEnd) {
3022add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao    delete (*cur);
3122add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao    ++cur;
3222add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao  }
3322add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao}
3422add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao
3537b74a387bb3993387029859c2d9d051c41c724eStephen HinesAttribute* AttributeSet::exists(const Attribute& pAttr) const {
3622add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao  if (m_Predefined == pAttr)
3722add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao    return const_cast<Attribute*>(&m_Predefined);
3822add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao
3922add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao  const_iterator cur = m_AttrSet.begin();
4022add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao  const_iterator aEnd = m_AttrSet.end();
4137b74a387bb3993387029859c2d9d051c41c724eStephen Hines  while (cur != aEnd) {
4222add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao    if (*(*cur) == pAttr) {
4322add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao      return *cur;
4422add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao    }
4522add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao    ++cur;
4622add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao  }
4722add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao  return NULL;
4822add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao}
4922add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao
5037b74a387bb3993387029859c2d9d051c41c724eStephen Hinesvoid AttributeSet::record(mcld::Attribute& pAttr) {
5122add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao  m_AttrSet.push_back(&pAttr);
5222add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao}
5322add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao
5437b74a387bb3993387029859c2d9d051c41c724eStephen Hines}  // namespace mcld
55