11031SN/A/* 21762SN/A * Copyright (c) 2004-2005 The Regents of The University of Michigan 31031SN/A * All rights reserved. 41031SN/A * 51031SN/A * Redistribution and use in source and binary forms, with or without 61031SN/A * modification, are permitted provided that the following conditions are 71031SN/A * met: redistributions of source code must retain the above copyright 81031SN/A * notice, this list of conditions and the following disclaimer; 91031SN/A * redistributions in binary form must reproduce the above copyright 101031SN/A * notice, this list of conditions and the following disclaimer in the 111031SN/A * documentation and/or other materials provided with the distribution; 121031SN/A * neither the name of the copyright holders nor the names of its 131031SN/A * contributors may be used to endorse or promote products derived from 141031SN/A * this software without specific prior written permission. 151031SN/A * 161031SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 171031SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 181031SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 191031SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 201031SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 211031SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 221031SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 231031SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 241031SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 251031SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 261031SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Nathan Binkert 291031SN/A */ 301031SN/A 311031SN/A#include "base/match.hh" 3211793Sbrandon.potter@amd.com 331031SN/A#include "base/str.hh" 341031SN/A 351031SN/Ausing namespace std; 361031SN/A 371031SN/AObjectMatch::ObjectMatch() 381031SN/A{ 391031SN/A} 401031SN/A 411031SN/AObjectMatch::ObjectMatch(const string &expr) 421031SN/A{ 431031SN/A setExpression(expr); 441031SN/A} 451031SN/A 461031SN/Avoid 4713804Sisaac.sanchez@bsc.esObjectMatch::add(const ObjectMatch &other) 4813804Sisaac.sanchez@bsc.es{ 4913804Sisaac.sanchez@bsc.es tokens.insert(tokens.end(), other.tokens.begin(), other.tokens.end()); 5013804Sisaac.sanchez@bsc.es} 5113804Sisaac.sanchez@bsc.es 5213804Sisaac.sanchez@bsc.esvoid 531031SN/AObjectMatch::setExpression(const string &expr) 541031SN/A{ 551031SN/A tokens.resize(1); 561031SN/A tokenize(tokens[0], expr, '.'); 571031SN/A} 581031SN/A 591031SN/Avoid 601031SN/AObjectMatch::setExpression(const vector<string> &expr) 611031SN/A{ 621031SN/A if (expr.empty()) { 631031SN/A tokens.resize(0); 641031SN/A } else { 651031SN/A tokens.resize(expr.size()); 666227Snate@binkert.org for (vector<string>::size_type i = 0; i < expr.size(); ++i) 671031SN/A tokenize(tokens[i], expr[i], '.'); 681031SN/A } 691031SN/A} 701031SN/A 711031SN/A/** 721031SN/A * @todo this should probably be changed to just use regular 731031SN/A * expression code 741031SN/A */ 751031SN/Abool 761031SN/AObjectMatch::domatch(const string &name) const 771031SN/A{ 781031SN/A vector<string> name_tokens; 791031SN/A tokenize(name_tokens, name, '.'); 801031SN/A int ntsize = name_tokens.size(); 811031SN/A 821031SN/A int num_expr = tokens.size(); 831031SN/A for (int i = 0; i < num_expr; ++i) { 841031SN/A const vector<string> &token = tokens[i]; 851031SN/A int jstop = token.size(); 861031SN/A 871031SN/A bool match = true; 881031SN/A for (int j = 0; j < jstop; ++j) { 891031SN/A if (j >= ntsize) 901031SN/A break; 911031SN/A 921031SN/A const string &var = token[j]; 931031SN/A if (var != "*" && var != name_tokens[j]) { 941031SN/A match = false; 951031SN/A break; 961031SN/A } 971031SN/A } 981031SN/A 9910231Ssteve.reinhardt@amd.com if (match) 1001031SN/A return true; 1011031SN/A } 1021031SN/A 1031031SN/A return false; 1041031SN/A} 1051031SN/A 106