Move rename/namewarn engine from parser.y to naming.c. The code was getting

too large to be in the parser.

Centralize the swig keys to avoid replication and wrong spellings.

Use more HashGetAttr where possible and other speed improvements
to compensate for the extra work introduced by the new rename/namewarn
mechanism.


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@8170 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2006-01-02 04:33:19 +00:00
commit 55005e98ee
18 changed files with 938 additions and 823 deletions

View file

@ -87,151 +87,5 @@ void cparse_normalize_void(Node *n) {
}
}
}
/* -----------------------------------------------------------------------------
* int need_protected(Node* n, int dirprot_mode)
*
* Detects when we need to fully register the protected member.
*
* ----------------------------------------------------------------------------- */
int need_protected(Node* n, int dirprot_mode)
{
/* First, 'n' looks like a function */
if (!dirprot_mode && !Swig_director_mode()) return 0;
if ((Strcmp(nodeType(n),"cdecl") == 0) &&
SwigType_isfunction(Getattr(n,"decl"))) {
String *storage = Getattr(n,"storage");
/* and the function is declared like virtual, or it has no
storage. This eliminates typedef, static and so on. */
return (!storage || (Strcmp(storage,"virtual") == 0));
} else if ((Strcmp(nodeType(n),"constructor") == 0)) {
return 1;
}
return 0;
}
/* -----------------------------------------------------------------------------
* int need_name_warning(Node *n)
*
* Detects if a node needs name warnings
*
* ----------------------------------------------------------------------------- */
int need_name_warning(Node *n)
{
int need = 1;
/*
we don't use name warnings for:
- class forwards, no symbol is generated at the target language.
- template declarations, only for real instances using %template(name).
- typedefs, they have no effect at the target language.
*/
if (Strcmp(nodeType(n),"classforward") == 0) {
need = 0;
} else if (Getattr(n,"templatetype")) {
need = 0;
} else {
String *storage = Getattr(n,"storage");
if (storage && (Strcmp(storage,"typedef") == 0)) {
need = 0;
}
}
return need;
}
int are_equivalent_nodes(Node* a, Node* b, int a_inclass)
{
/* they must have the same type */
SwigType *ta = nodeType(a);
SwigType *tb = nodeType(b);
if (Cmp(ta, tb) != 0) return 0;
/* cdecl case */
if (Cmp(ta, "cdecl") == 0) {
/* typedef */
String *a_storage = Getattr(a,"storage");
String *b_storage = Getattr(b,"storage");
if ((Cmp(a_storage,"typedef") == 0)
|| (Cmp(b_storage,"typedef") == 0)) {
if (Cmp(a_storage, b_storage) == 0) {
String *a_type = (Getattr(a,"type"));
String *b_type = (Getattr(b,"type"));
if (Cmp(a_type, b_type) == 0) return 1;
}
return 0;
}
/* static functions */
if ((Cmp(a_storage, "static") == 0)
|| (Cmp(b_storage, "static") == 0)) {
if (Cmp(a_storage, b_storage) != 0) return 0;
}
/* friend methods */
if (!a_inclass || (Cmp(a_storage,"friend") == 0)) {
/* check declaration */
String *a_decl = (Getattr(a,"decl"));
String *b_decl = (Getattr(b,"decl"));
if (Cmp(a_decl, b_decl) == 0) {
/* check return type */
String *a_type = (Getattr(a,"type"));
String *b_type = (Getattr(b,"type"));
if (Cmp(a_type, b_type) == 0) {
/* check parameters */
Parm *ap = (Getattr(a,"parms"));
Parm *bp = (Getattr(b,"parms"));
while (ap && bp) {
SwigType *at = Getattr(ap,"type");
SwigType *bt = Getattr(bp,"type");
if (Cmp(at, bt) != 0) return 0;
ap = nextSibling(ap);
bp = nextSibling(bp);
}
if (ap || bp) {
return 0;
} else {
Node *a_template = Getattr(a,"template");
Node *b_template = Getattr(b,"template");
/* Not equivalent if one is a template instantiation (via %template) and the other is a non-templated function */
if ((a_template && !b_template) || (!a_template && b_template)) return 0;
}
return 1;
}
}
}
} else {
/* %constant case */
String *a_storage = Getattr(a,"storage");
String *b_storage = Getattr(b,"storage");
if ((Cmp(a_storage, "%constant") == 0)
|| (Cmp(b_storage, "%constant") == 0)) {
if (Cmp(a_storage, b_storage) == 0) {
String *a_type = (Getattr(a,"type"));
String *b_type = (Getattr(b,"type"));
if ((Cmp(a_type, b_type) == 0)
&& (Cmp(Getattr(a,"value"), Getattr(b,"value")) == 0))
return 1;
}
return 0;
}
}
return 0;
}
int need_redefined_warn(Node* a, Node* b, int InClass)
{
String *a_symname = Getattr(a,"sym:name");
String *b_symname = Getattr(b,"sym:name");
/* always send a warning if a 'rename' is involved */
if ((a_symname && Cmp(a_symname,Getattr(a,"name")))
|| (b_symname && Cmp(b_symname,Getattr(b,"name"))))
return 1;
return !are_equivalent_nodes(a, b, InClass);
}