mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-23 18:43:03 +01:00
big class Symbol cleanup
This commit is contained in:
parent
10e311b36d
commit
4712bad7b5
@ -27,16 +27,17 @@
|
||||
#include "../jrd/jrd.h"
|
||||
#include "../jrd/val.h"
|
||||
#include "../jrd/err_proto.h"
|
||||
#include "../jrd/sym_proto.h"
|
||||
#include "../jrd/sym.h"
|
||||
#include "../jrd/thd_proto.h"
|
||||
|
||||
|
||||
using namespace Jrd;
|
||||
|
||||
static SSHORT hash_func(const SCHAR*);
|
||||
namespace {
|
||||
SSHORT hash_func(const Firebird::string&);
|
||||
}
|
||||
|
||||
|
||||
void SYM_insert(Symbol* symbol)
|
||||
void Symbol::insert()
|
||||
{
|
||||
/**************************************
|
||||
*
|
||||
@ -50,22 +51,24 @@ void SYM_insert(Symbol* symbol)
|
||||
**************************************/
|
||||
Database* dbb = GET_DBB;
|
||||
|
||||
const int h = hash_func(symbol->sym_string);
|
||||
const int h = hash_func(sym_string);
|
||||
|
||||
for (Symbol* old = dbb->dbb_hash_table[h]; old; old = old->sym_collision) {
|
||||
if (!strcmp(symbol->sym_string, old->sym_string)) {
|
||||
symbol->sym_homonym = old->sym_homonym;
|
||||
old->sym_homonym = symbol;
|
||||
for (Symbol* old = dbb->dbb_hash_table[h]; old; old = old->sym_collision)
|
||||
{
|
||||
if (sym_string == old->sym_string)
|
||||
{
|
||||
sym_homonym = old->sym_homonym;
|
||||
old->sym_homonym = this;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
symbol->sym_collision = dbb->dbb_hash_table[h];
|
||||
dbb->dbb_hash_table[h] = symbol;
|
||||
sym_collision = dbb->dbb_hash_table[h];
|
||||
dbb->dbb_hash_table[h] = this;
|
||||
}
|
||||
|
||||
|
||||
Symbol* SYM_lookup(const TEXT* string)
|
||||
Symbol* Symbol::lookup(const Firebird::string& string)
|
||||
{
|
||||
/**************************************
|
||||
*
|
||||
@ -82,7 +85,7 @@ Symbol* SYM_lookup(const TEXT* string)
|
||||
for (Symbol* symbol = dbb->dbb_hash_table[hash_func(string)]; symbol;
|
||||
symbol = symbol->sym_collision)
|
||||
{
|
||||
if (!strcmp(string, symbol->sym_string))
|
||||
if (string == symbol->sym_string)
|
||||
return symbol;
|
||||
}
|
||||
|
||||
@ -90,7 +93,7 @@ Symbol* SYM_lookup(const TEXT* string)
|
||||
}
|
||||
|
||||
|
||||
void SYM_remove(Symbol* symbol)
|
||||
void Symbol::remove()
|
||||
{
|
||||
/**************************************
|
||||
*
|
||||
@ -104,20 +107,20 @@ void SYM_remove(Symbol* symbol)
|
||||
**************************************/
|
||||
Database* dbb = GET_DBB;
|
||||
|
||||
const int h = hash_func(symbol->sym_string);
|
||||
const int h = hash_func(sym_string);
|
||||
|
||||
for (Symbol** next = &dbb->dbb_hash_table[h]; *next;
|
||||
next = &(*next)->sym_collision)
|
||||
{
|
||||
if (symbol == *next) {
|
||||
Symbol* homonym = symbol->sym_homonym;
|
||||
if (this == *next) {
|
||||
Symbol* homonym = sym_homonym;
|
||||
if (homonym) {
|
||||
homonym->sym_collision = symbol->sym_collision;
|
||||
homonym->sym_collision = sym_collision;
|
||||
*next = homonym;
|
||||
return;
|
||||
}
|
||||
else {
|
||||
*next = symbol->sym_collision;
|
||||
*next = sym_collision;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -125,8 +128,8 @@ void SYM_remove(Symbol* symbol)
|
||||
for (Symbol** ptr = &(*next)->sym_homonym; *ptr;
|
||||
ptr = &(*ptr)->sym_homonym)
|
||||
{
|
||||
if (symbol == *ptr) {
|
||||
*ptr = symbol->sym_homonym;
|
||||
if (this == *ptr) {
|
||||
*ptr = sym_homonym;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -136,8 +139,9 @@ void SYM_remove(Symbol* symbol)
|
||||
BUGCHECK(164); /* msg 164 failed to remove symbol from hash table */
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
static SSHORT hash_func(const SCHAR* string)
|
||||
SSHORT hash_func(const Firebird::string& str)
|
||||
{
|
||||
/**************************************
|
||||
*
|
||||
@ -155,12 +159,12 @@ static SSHORT hash_func(const SCHAR* string)
|
||||
|
||||
int value = 0;
|
||||
|
||||
SCHAR c;
|
||||
while ( (c = *string++) ) {
|
||||
value = (value << 1) + UPPER7(c);
|
||||
for (const char *s = str.c_str(); *s; s++)
|
||||
{
|
||||
value = (value << 1) + UPPER7(*s);
|
||||
}
|
||||
|
||||
return ((value >= 0) ? value : -value) % HASH_SIZE;
|
||||
}
|
||||
|
||||
|
||||
} //noname namespace
|
||||
|
64
src/jrd/sym.h
Normal file
64
src/jrd/sym.h
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* PROGRAM: JRD Access Method
|
||||
* MODULE: sym.h
|
||||
* DESCRIPTION: Header file for sym.cpp
|
||||
*
|
||||
* The contents of this file are subject to the Interbase Public
|
||||
* License Version 1.0 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy
|
||||
* of the License at http://www.Inprise.com/IPL.html
|
||||
*
|
||||
* Software distributed under the License is distributed on an
|
||||
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
|
||||
* or implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code was created by Inprise Corporation
|
||||
* and its predecessors. Portions created by Inprise Corporation are
|
||||
* Copyright (C) Inprise Corporation.
|
||||
*
|
||||
* All Rights Reserved.
|
||||
* Contributor(s): ______________________________________.
|
||||
*/
|
||||
|
||||
#ifndef JRD_SYM_H
|
||||
#define JRD_SYM_H
|
||||
|
||||
namespace Jrd {
|
||||
/* symbol definitions */
|
||||
|
||||
class Symbol : public pool_alloc<type_sym>
|
||||
{
|
||||
private:
|
||||
Symbol* sym_collision; /* collision pointer */
|
||||
|
||||
public:
|
||||
typedef enum sym_t {
|
||||
rel, /* relation block */
|
||||
fld, /* field block */
|
||||
fun, /* UDF function block */
|
||||
prc, /* stored procedure block */
|
||||
sql, /* SQL request cache block */
|
||||
blr, /* BLR request cache block */
|
||||
label /* CVC: I need to track labels if LEAVE is implemented. */
|
||||
} SYM_T;
|
||||
Firebird::string sym_string; // symbol value
|
||||
SYM_T sym_type; /* symbol type */
|
||||
BLK sym_object; /* general pointer to object */
|
||||
Symbol* sym_homonym; /* homonym pointer */
|
||||
|
||||
public:
|
||||
explicit Symbol(MemoryPool& p, const Firebird::string& val,
|
||||
SYM_T type, BLK object)
|
||||
: sym_collision(0), sym_string(p, val), sym_type(type),
|
||||
sym_object(object), sym_homonym(0) { }
|
||||
void insert();
|
||||
static Symbol* lookup(const Firebird::string&);
|
||||
void remove();
|
||||
};
|
||||
|
||||
} //namespace Jrd
|
||||
|
||||
|
||||
#endif // JRD_SYM_H
|
||||
|
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* PROGRAM: JRD Access Method
|
||||
* MODULE: sym_proto.h
|
||||
* DESCRIPTION: Prototype header file for sym.cpp
|
||||
*
|
||||
* The contents of this file are subject to the Interbase Public
|
||||
* License Version 1.0 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy
|
||||
* of the License at http://www.Inprise.com/IPL.html
|
||||
*
|
||||
* Software distributed under the License is distributed on an
|
||||
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
|
||||
* or implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code was created by Inprise Corporation
|
||||
* and its predecessors. Portions created by Inprise Corporation are
|
||||
* Copyright (C) Inprise Corporation.
|
||||
*
|
||||
* All Rights Reserved.
|
||||
* Contributor(s): ______________________________________.
|
||||
*/
|
||||
|
||||
#ifndef JRD_SYM_PROTO_H
|
||||
#define JRD_SYM_PROTO_H
|
||||
|
||||
namespace Jrd {
|
||||
class Symbol;
|
||||
}
|
||||
|
||||
void SYM_insert(Jrd::Symbol*);
|
||||
Jrd::Symbol* SYM_lookup(const TEXT*);
|
||||
void SYM_remove(Jrd::Symbol*);
|
||||
|
||||
#endif // JRD_SYM_PROTO_H
|
||||
|
Loading…
Reference in New Issue
Block a user