1 /* 2 * (C) Copyright 2001-2015 Diomidis Spinellis 3 * 4 * This file is part of CScout. 5 * 6 * CScout is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * CScout is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with CScout. If not, see <http://www.gnu.org/licenses/>. 18 * 19 * 20 * An identifier equivalence class. 21 * Contains all tokids that belong to the same class 22 * 23 */ 24 25 #ifndef ECLASS_ 26 #define ECLASS_ 27 28 #include <deque> 29 #include <vector> 30 31 using namespace std; 32 33 #include "attr.h" 34 #include "tokid.h" 35 #include "tokmap.h" 36 37 typedef set<Tokid> setTokid; 38 39 class Call; 40 41 class Eclass { 42 private: 43 int len; // Identifier length 44 setTokid members; // Class members 45 Attributes attr; 46 public: 47 // An equivalence class shall know its length 48 inline Eclass(int len); 49 // It can be constructed from an initiall Tokid 50 inline Eclass(Tokid t, int len); 51 // Add t to the class; also updates the Tokmap 52 void add_tokid(Tokid t); 53 // Split an equivalence class after the (0-based) character position 54 // pos returning the new EC receiving the split Tokids 55 Eclass *split(int pos); 56 // Merge two equivalence classes returning the resulting one 57 // After the merger the values of a and b are undefined 58 friend Eclass *merge(Eclass *a, Eclass *b); 59 // Return length get_len()60 int get_len() const { return len; } 61 // Return number of members get_size()62 int get_size() { return members.size(); } 63 friend ostream& operator<<(ostream& o,const Eclass& ec); get_members(void)64 const setTokid & get_members(void) const { return members; } 65 // Files where the this appears 66 IFSet sorted_files(); 67 // Functions where the this appears 68 set <Call *> functions(); 69 // Other accessor functions set_attribute(int v)70 void set_attribute(int v) { attr.set_attribute(v); } get_attribute(int v)71 bool get_attribute(int v) { return attr.get_attribute(v); } is_identifier()72 bool is_identifier() { return attr.is_identifier(); } 73 // Return true if this equivalence class is unintentionally unused 74 bool is_unused(); merge_attributes(Eclass * b)75 void merge_attributes(Eclass *b) { attr.merge_with(b->attr); } 76 // Remove references to the equivalence class from the tokid map 77 // Should be called when we delete the ec for good 78 void remove_from_tokid_map(); 79 }; 80 81 inline Eclass(int l)82Eclass::Eclass(int l) 83 : len(l) 84 { 85 } 86 87 inline Eclass(Tokid t,int l)88Eclass::Eclass(Tokid t, int l) 89 : len(l) 90 { 91 add_tokid(t); 92 } 93 94 #endif /* ECLASS_ */ 95