Replace uses of the old List generation code with new template versions

This commit is contained in:
Tim Wojtulewicz 2019-07-02 18:43:01 -07:00 committed by Jon Siwek
parent 29836b47d0
commit 237c7e4e15
17 changed files with 57 additions and 94 deletions

View file

@ -6,31 +6,24 @@
#include "List.h" #include "List.h"
class Expr; class Expr;
declare(PList,Expr); typedef PList<Expr> expr_list;
typedef PList(Expr) expr_list;
class ID; class ID;
declare(PList,ID); typedef PList<ID> id_list;
typedef PList(ID) id_list;
class Val; class Val;
declare(PList,Val); typedef PList<Val> val_list;
typedef PList(Val) val_list;
class Stmt; class Stmt;
declare(PList,Stmt); typedef PList<Stmt> stmt_list;
typedef PList(Stmt) stmt_list;
class BroType; class BroType;
declare(PList,BroType); typedef PList<BroType> type_list;
typedef PList(BroType) type_list;
class Attr; class Attr;
declare(PList,Attr); typedef PList<Attr> attr_list;
typedef PList(Attr) attr_list;
class Timer; class Timer;
declare(PList,Timer); typedef PList<Timer> timer_list;
typedef PList(Timer) timer_list;
#endif #endif

View file

@ -5,8 +5,7 @@
#include "List.h" #include "List.h"
declare(List,ptr_compat_int); typedef List<ptr_compat_int> int_list;
typedef List(ptr_compat_int) int_list;
class CCL { class CCL {
public: public:

View file

@ -50,8 +50,7 @@ private:
int current_level; int current_level;
int suspend_level; int suspend_level;
declare(PList, void); typedef PList<void> voidp_list;
typedef PList(void) voidp_list;
voidp_list states; voidp_list states;
}; };

View file

@ -23,8 +23,7 @@ class EventHandler;
class RecordType; class RecordType;
class DNS_Mgr_Request; class DNS_Mgr_Request;
declare(PList,DNS_Mgr_Request); typedef PList<DNS_Mgr_Request> DNS_mgr_request_list;
typedef PList(DNS_Mgr_Request) DNS_mgr_request_list;
struct nb_dns_info; struct nb_dns_info;
struct nb_dns_result; struct nb_dns_result;

View file

@ -50,9 +50,9 @@ public:
} }
int bucket, offset; int bucket, offset;
PList(DictEntry)** ttbl; PList<DictEntry>** ttbl;
const int* num_buckets_p; const int* num_buckets_p;
PList(DictEntry) inserted; // inserted while iterating PList<DictEntry> inserted; // inserted while iterating
}; };
Dictionary::Dictionary(dict_order ordering, int initial_size) Dictionary::Dictionary(dict_order ordering, int initial_size)
@ -61,7 +61,7 @@ Dictionary::Dictionary(dict_order ordering, int initial_size)
tbl2 = 0; tbl2 = 0;
if ( ordering == ORDERED ) if ( ordering == ORDERED )
order = new PList(DictEntry); order = new PList<DictEntry>;
else else
order = 0; order = 0;
@ -99,7 +99,7 @@ void Dictionary::DeInit()
for ( int i = 0; i < num_buckets; ++i ) for ( int i = 0; i < num_buckets; ++i )
if ( tbl[i] ) if ( tbl[i] )
{ {
PList(DictEntry)* chain = tbl[i]; PList<DictEntry>* chain = tbl[i];
loop_over_list(*chain, j) loop_over_list(*chain, j)
{ {
DictEntry* e = (*chain)[j]; DictEntry* e = (*chain)[j];
@ -119,7 +119,7 @@ void Dictionary::DeInit()
for ( int i = 0; i < num_buckets2; ++i ) for ( int i = 0; i < num_buckets2; ++i )
if ( tbl2[i] ) if ( tbl2[i] )
{ {
PList(DictEntry)* chain = tbl2[i]; PList<DictEntry>* chain = tbl2[i];
loop_over_list(*chain, j) loop_over_list(*chain, j)
{ {
DictEntry* e = (*chain)[j]; DictEntry* e = (*chain)[j];
@ -141,7 +141,7 @@ void* Dictionary::Lookup(const void* key, int key_size, hash_t hash) const
return 0; return 0;
hash_t h; hash_t h;
PList(DictEntry)* chain; PList<DictEntry>* chain;
// Figure out which hash table to look in. // Figure out which hash table to look in.
h = hash % num_buckets; h = hash % num_buckets;
@ -199,7 +199,7 @@ void* Dictionary::Remove(const void* key, int key_size, hash_t hash,
return 0; return 0;
hash_t h; hash_t h;
PList(DictEntry)* chain; PList<DictEntry>* chain;
int* num_entries_ptr; int* num_entries_ptr;
// Figure out which hash table to look in // Figure out which hash table to look in
@ -240,7 +240,7 @@ void* Dictionary::Remove(const void* key, int key_size, hash_t hash,
} }
void* Dictionary::DoRemove(DictEntry* entry, hash_t h, void* Dictionary::DoRemove(DictEntry* entry, hash_t h,
PList(DictEntry)* chain, int chain_offset) PList<DictEntry>* chain, int chain_offset)
{ {
void* entry_value = entry->value; void* entry_value = entry->value;
@ -301,7 +301,7 @@ void* Dictionary::NextEntry(HashKey*& h, IterCookie*& cookie, int return_hash) c
{ {
if ( ! tbl && ! tbl2 ) if ( ! tbl && ! tbl2 )
{ {
const_cast<PList(IterCookie)*>(&cookies)->remove(cookie); const_cast<PList<IterCookie>*>(&cookies)->remove(cookie);
delete cookie; delete cookie;
cookie = 0; cookie = 0;
return 0; return 0;
@ -326,7 +326,7 @@ void* Dictionary::NextEntry(HashKey*& h, IterCookie*& cookie, int return_hash) c
int b = cookie->bucket; int b = cookie->bucket;
int o = cookie->offset; int o = cookie->offset;
PList(DictEntry)** ttbl; PList<DictEntry>** ttbl;
const int* num_buckets_p; const int* num_buckets_p;
if ( ! cookie->ttbl ) if ( ! cookie->ttbl )
@ -368,7 +368,7 @@ void* Dictionary::NextEntry(HashKey*& h, IterCookie*& cookie, int return_hash) c
// FIXME: I don't like removing the const here. But is there // FIXME: I don't like removing the const here. But is there
// a better way? // a better way?
const_cast<PList(IterCookie)*>(&cookies)->remove(cookie); const_cast<PList<IterCookie>*>(&cookies)->remove(cookie);
delete cookie; delete cookie;
cookie = 0; cookie = 0;
return 0; return 0;
@ -387,7 +387,7 @@ void* Dictionary::NextEntry(HashKey*& h, IterCookie*& cookie, int return_hash) c
void Dictionary::Init(int size) void Dictionary::Init(int size)
{ {
num_buckets = NextPrime(size); num_buckets = NextPrime(size);
tbl = new PList(DictEntry)*[num_buckets]; tbl = new PList<DictEntry>*[num_buckets];
for ( int i = 0; i < num_buckets; ++i ) for ( int i = 0; i < num_buckets; ++i )
tbl[i] = 0; tbl[i] = 0;
@ -399,7 +399,7 @@ void Dictionary::Init(int size)
void Dictionary::Init2(int size) void Dictionary::Init2(int size)
{ {
num_buckets2 = NextPrime(size); num_buckets2 = NextPrime(size);
tbl2 = new PList(DictEntry)*[num_buckets2]; tbl2 = new PList<DictEntry>*[num_buckets2];
for ( int i = 0; i < num_buckets2; ++i ) for ( int i = 0; i < num_buckets2; ++i )
tbl2[i] = 0; tbl2[i] = 0;
@ -413,7 +413,7 @@ void* Dictionary::Insert(DictEntry* new_entry, int copy_key)
if ( ! tbl ) if ( ! tbl )
Init(DEFAULT_DICT_SIZE); Init(DEFAULT_DICT_SIZE);
PList(DictEntry)** ttbl; PList<DictEntry>** ttbl;
int* num_entries_ptr; int* num_entries_ptr;
int* max_num_entries_ptr; int* max_num_entries_ptr;
hash_t h = new_entry->hash % num_buckets; hash_t h = new_entry->hash % num_buckets;
@ -438,7 +438,7 @@ void* Dictionary::Insert(DictEntry* new_entry, int copy_key)
max_num_entries_ptr = &max_num_entries2; max_num_entries_ptr = &max_num_entries2;
} }
PList(DictEntry)* chain = ttbl[h]; PList<DictEntry>* chain = ttbl[h];
int n = new_entry->len; int n = new_entry->len;
@ -460,7 +460,7 @@ void* Dictionary::Insert(DictEntry* new_entry, int copy_key)
} }
else else
// Create new chain. // Create new chain.
chain = ttbl[h] = new PList(DictEntry); chain = ttbl[h] = new PList<DictEntry>;
// If we got this far, then we couldn't use an existing copy // If we got this far, then we couldn't use an existing copy
// of the key, so make a new one if necessary. // of the key, so make a new one if necessary.
@ -545,7 +545,7 @@ void Dictionary::MoveChains()
do do
{ {
PList(DictEntry)* chain = tbl[tbl_next_ind++]; PList<DictEntry>* chain = tbl[tbl_next_ind++];
if ( ! chain ) if ( ! chain )
continue; continue;
@ -605,13 +605,13 @@ unsigned int Dictionary::MemoryAllocation() const
for ( int i = 0; i < num_buckets; ++i ) for ( int i = 0; i < num_buckets; ++i )
if ( tbl[i] ) if ( tbl[i] )
{ {
PList(DictEntry)* chain = tbl[i]; PList<DictEntry>* chain = tbl[i];
loop_over_list(*chain, j) loop_over_list(*chain, j)
size += padded_sizeof(DictEntry) + pad_size((*chain)[j]->len); size += padded_sizeof(DictEntry) + pad_size((*chain)[j]->len);
size += chain->MemoryAllocation(); size += chain->MemoryAllocation();
} }
size += pad_size(num_buckets * sizeof(PList(DictEntry)*)); size += pad_size(num_buckets * sizeof(PList<DictEntry>*));
if ( order ) if ( order )
size += order->MemoryAllocation(); size += order->MemoryAllocation();
@ -621,13 +621,13 @@ unsigned int Dictionary::MemoryAllocation() const
for ( int i = 0; i < num_buckets2; ++i ) for ( int i = 0; i < num_buckets2; ++i )
if ( tbl2[i] ) if ( tbl2[i] )
{ {
PList(DictEntry)* chain = tbl2[i]; PList<DictEntry>* chain = tbl2[i];
loop_over_list(*chain, j) loop_over_list(*chain, j)
size += padded_sizeof(DictEntry) + pad_size((*chain)[j]->len); size += padded_sizeof(DictEntry) + pad_size((*chain)[j]->len);
size += chain->MemoryAllocation(); size += chain->MemoryAllocation();
} }
size += pad_size(num_buckets2 * sizeof(PList(DictEntry)*)); size += pad_size(num_buckets2 * sizeof(PList<DictEntry>*));
} }
return size; return size;

View file

@ -10,9 +10,6 @@ class Dictionary;
class DictEntry; class DictEntry;
class IterCookie; class IterCookie;
declare(PList,DictEntry);
declare(PList,IterCookie);
// Type indicating whether the dictionary should keep track of the order // Type indicating whether the dictionary should keep track of the order
// of insertions. // of insertions.
typedef enum { ORDERED, UNORDERED } dict_order; typedef enum { ORDERED, UNORDERED } dict_order;
@ -132,7 +129,7 @@ private:
void* Insert(DictEntry* entry, int copy_key); void* Insert(DictEntry* entry, int copy_key);
void* DoRemove(DictEntry* entry, hash_t h, void* DoRemove(DictEntry* entry, hash_t h,
PList(DictEntry)* chain, int chain_offset); PList<DictEntry>* chain, int chain_offset);
int NextPrime(int n) const; int NextPrime(int n) const;
int IsPrime(int n) const; int IsPrime(int n) const;
@ -162,7 +159,7 @@ private:
// When we're resizing, we'll have tbl (old) and tbl2 (new) // When we're resizing, we'll have tbl (old) and tbl2 (new)
// tbl_next_ind keeps track of how much we've moved to tbl2 // tbl_next_ind keeps track of how much we've moved to tbl2
// (it's the next index we're going to move). // (it's the next index we're going to move).
PList(DictEntry)** tbl; PList<DictEntry>** tbl;
int num_buckets; int num_buckets;
int num_entries; int num_entries;
int max_num_entries; int max_num_entries;
@ -171,7 +168,7 @@ private:
int thresh_entries; int thresh_entries;
// Resizing table (replicates tbl above). // Resizing table (replicates tbl above).
PList(DictEntry)** tbl2; PList<DictEntry>** tbl2;
int num_buckets2; int num_buckets2;
int num_entries2; int num_entries2;
int max_num_entries2; int max_num_entries2;
@ -180,10 +177,10 @@ private:
hash_t tbl_next_ind; hash_t tbl_next_ind;
PList(DictEntry)* order; PList<DictEntry>* order;
dict_delete_func delete_func; dict_delete_func delete_func;
PList(IterCookie) cookies; PList<IterCookie> cookies;
}; };

View file

@ -22,8 +22,7 @@ public:
// Returns a list of all local handlers that match the given pattern. // Returns a list of all local handlers that match the given pattern.
// Passes ownership of list. // Passes ownership of list.
typedef const char constchar; // PList doesn't like "const char" typedef const char constchar; // PList doesn't like "const char"
declare(PList, constchar); typedef PList<constchar> string_list;
typedef PList(constchar) string_list;
string_list* Match(RE_Matcher* pattern); string_list* Match(RE_Matcher* pattern);
// Marks a handler as handling errors. Error handler will not be called // Marks a handler as handling errors. Error handler will not be called

View file

@ -9,8 +9,7 @@
class NFA_State; class NFA_State;
class EquivClass; class EquivClass;
declare(PList,NFA_State); typedef PList<NFA_State> NFA_state_list;
typedef PList(NFA_State) NFA_state_list;
#define NO_ACCEPT 0 #define NO_ACCEPT 0

View file

@ -24,7 +24,6 @@ class DFA_State;
declare(PDict,char); declare(PDict,char);
declare(PDict,CCL); declare(PDict,CCL);
declare(PList,CCL);
extern int case_insensitive; extern int case_insensitive;
extern CCL* curr_ccl; extern CCL* curr_ccl;
@ -125,7 +124,7 @@ protected:
PDict(char) defs; PDict(char) defs;
PDict(CCL) ccl_dict; PDict(CCL) ccl_dict;
PList(CCL) ccl_list; PList<CCL> ccl_list;
EquivClass equiv_class; EquivClass equiv_class;
int* ecs; int* ecs;
DFA_Machine* dfa; DFA_Machine* dfa;

View file

@ -14,8 +14,7 @@ class RuleHdrTest;
class Rule; class Rule;
declare(PList, Rule); typedef PList<Rule> rule_list;
typedef PList(Rule) rule_list;
declare(PDict, Rule); declare(PDict, Rule);
typedef PDict(Rule) rule_dict; typedef PDict(Rule) rule_dict;
@ -61,14 +60,9 @@ private:
void SortHdrTests(); void SortHdrTests();
declare(PList, RuleAction); typedef PList<RuleAction> rule_action_list;
typedef PList(RuleAction) rule_action_list; typedef PList<RuleCondition> rule_condition_list;
typedef PList<RuleHdrTest> rule_hdr_test_list;
declare(PList, RuleCondition);
typedef PList(RuleCondition) rule_condition_list;
declare(PList, RuleHdrTest);
typedef PList(RuleHdrTest) rule_hdr_test_list;
rule_hdr_test_list hdr_tests; rule_hdr_test_list hdr_tests;
rule_condition_list conditions; rule_condition_list conditions;
@ -82,8 +76,7 @@ private:
bool negate; // negate test bool negate; // negate test
}; };
declare(PList, Precond); typedef PList<Precond> precond_list;
typedef PList(Precond) precond_list;
precond_list preconds; precond_list preconds;
rule_list dependents; // rules w/ us as a precondition rule_list dependents; // rules w/ us as a precondition
@ -101,8 +94,7 @@ private:
uint32 depth; uint32 depth;
}; };
declare(PList, Pattern); typedef PList<Pattern> pattern_list;
typedef PList(Pattern) pattern_list;
pattern_list patterns; pattern_list patterns;
Rule* next; // Linkage within RuleHdrTest tree: Rule* next; // Linkage within RuleHdrTest tree:

View file

@ -56,13 +56,9 @@ struct MaskedValue {
uint32 mask; uint32 mask;
}; };
declare(PList, MaskedValue); typedef PList<MaskedValue> maskedvalue_list;
typedef PList(MaskedValue) maskedvalue_list; typedef PList<char> string_list;
typedef PList<BroString> bstr_list;
typedef PList(char) string_list;
declare(PList, BroString);
typedef PList(BroString) bstr_list;
// Get values from Bro's script-level variables. // Get values from Bro's script-level variables.
extern void id_to_maskedvallist(const char* id, maskedvalue_list* append_to, extern void id_to_maskedvallist(const char* id, maskedvalue_list* append_to,
@ -119,8 +115,7 @@ private:
int_list ids; // (only needed for debugging) int_list ids; // (only needed for debugging)
}; };
declare(PList, PatternSet); typedef PList<PatternSet> pattern_set_list;
typedef PList(PatternSet) pattern_set_list;
pattern_set_list psets[Rule::TYPES]; pattern_set_list psets[Rule::TYPES];
// List of rules belonging to this node. // List of rules belonging to this node.
@ -136,8 +131,7 @@ private:
int level; // level within the tree int level; // level within the tree
}; };
declare(PList, RuleHdrTest); typedef PList<RuleHdrTest> rule_hdr_test_list;
typedef PList(RuleHdrTest) rule_hdr_test_list;
// RuleEndpointState keeps the per-stream matching state of one // RuleEndpointState keeps the per-stream matching state of one
// connection endpoint. // connection endpoint.
@ -172,8 +166,7 @@ private:
Rule::PatternType type; Rule::PatternType type;
}; };
declare(PList, Matcher); typedef PList<Matcher> matcher_list;
typedef PList(Matcher) matcher_list;
bool is_orig; bool is_orig;
analyzer::Analyzer* analyzer; analyzer::Analyzer* analyzer;
@ -212,8 +205,7 @@ private:
RE_Match_State* state; RE_Match_State* state;
}; };
declare(PList, Matcher); typedef PList<Matcher> matcher_list;
typedef PList(Matcher) matcher_list;
matcher_list matchers; matcher_list matchers;
}; };

View file

@ -7,8 +7,7 @@
#include "Scope.h" #include "Scope.h"
#include "Reporter.h" #include "Reporter.h"
declare(PList,Scope); typedef PList<Scope> scope_list;
typedef PList(Scope) scope_list;
static scope_list scopes; static scope_list scopes;
static Scope* top_scope; static Scope* top_scope;

View file

@ -195,8 +195,7 @@ protected:
Stmt* s; Stmt* s;
}; };
declare(PList,Case); typedef PList<Case> case_list;
typedef PList(Case) case_list;
class SwitchStmt : public ExprStmt { class SwitchStmt : public ExprStmt {
public: public:

View file

@ -455,8 +455,7 @@ public:
const char* id; const char* id;
}; };
declare(PList,TypeDecl); typedef PList<TypeDecl> type_decl_list;
typedef PList(TypeDecl) type_decl_list;
class RecordType : public BroType { class RecordType : public BroType {
public: public:

View file

@ -84,7 +84,6 @@ protected:
}; };
// declare(PList, MIME_Header);
typedef vector<MIME_Header*> MIME_HeaderList; typedef vector<MIME_Header*> MIME_HeaderList;
class MIME_Entity { class MIME_Entity {

View file

@ -126,8 +126,7 @@ public:
// A stack of input buffers we're scanning. file_stack[len-1] is the // A stack of input buffers we're scanning. file_stack[len-1] is the
// top of the stack. // top of the stack.
declare(PList,FileInfo); static PList<FileInfo> file_stack;
static PList(FileInfo) file_stack;
#define RET_CONST(v) \ #define RET_CONST(v) \
{ \ { \

View file

@ -360,7 +360,7 @@ Val* do_sub(StringVal* str_val, RE_Matcher* re, StringVal* repl, int do_all)
// cut_points is a set of pairs of indices in str that should // cut_points is a set of pairs of indices in str that should
// be removed/replaced. A pair <x,y> means "delete starting // be removed/replaced. A pair <x,y> means "delete starting
// at offset x, up to but not including offset y". // at offset x, up to but not including offset y".
List(ptr_compat_int) cut_points; // where RE matches pieces of str List<ptr_compat_int> cut_points; // where RE matches pieces of str
int size = 0; // size of result int size = 0; // size of result