X-Git-Url: http://andersk.mit.edu/gitweb/splint.git/blobdiff_plain/616915ddfdcba888735f45cbd9c26c9b5383ee2c..495af944dbec7ce9480ebe3d955aed7aff85a754:/src/uentryList.c diff --git a/src/uentryList.c b/src/uentryList.c index 773af21..3eed5b5 100644 --- a/src/uentryList.c +++ b/src/uentryList.c @@ -1,6 +1,6 @@ /* -** LCLint - annotation-assisted static program checker -** Copyright (C) 1994-2000 University of Virginia, +** Splint - annotation-assisted static program checker +** Copyright (C) 1994-2002 University of Virginia, ** Massachusetts Institute of Technology ** ** This program is free software; you can redistribute it and/or modify it @@ -17,15 +17,15 @@ ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, ** MA 02111-1307, USA. ** -** For information on lclint: lclint-request@cs.virginia.edu -** To report a bug: lclint-bug@cs.virginia.edu -** For more information: http://lclint.cs.virginia.edu +** For information on splint: info@splint.org +** To report a bug: splint-bug@splint.org +** For more information: http://www.splint.org */ /* ** uentryList.c (from slist_template.c) */ -# include "lclintMacros.nf" +# include "splintMacros.nf" # include "basic.h" /*@only@*/ /*@notnull@*/ uentryList @@ -155,6 +155,91 @@ uentryList uentryList_add (uentryList s, /*@keep@*/ uentry el) return (st); } +cstring uentryList_unparseParamsComplete (uentryList s) +{ + int i; + cstring st = cstring_undefined; + cstring cur; + + if (uentryList_isUndefined (s)) + { + return st; + } + else if (uentryList_isVoid (s)) + { + return (cstring_makeLiteral ("void")); + } + else + { + for (i = 0; i < uentryList_size (s); i++) + { + cstring cQuals, name, ctypeName; + + cQuals = qualList_unparse(s->elements[i]->cQuals); + + name = uentry_getName(s->elements[i]); + + if (ctype_isFunction (uentry_getType (s->elements[i])) ) + { + cur = ctype_unparseFunctionPointer(uentry_getType (s->elements[i] ), cQuals, name); + cstring_free(cQuals); + } + else + { + ctypeName = message("%s", ctype_unparse(uentry_getType (s->elements[i] ) ) ); + + if (ctype_isFixedArray (uentry_getType (s->elements[i] ) ) ) + { + cstring aType, aSize; + aType = cstring_beforeChar(ctypeName, '['); + aSize = cstring_afterChar(ctypeName, '['); + + cur = message ("%q %q %q %s", + cQuals, aType, name, aSize ); + + // cstring_free(ctypeName); + } + else if (ctype_isArray (uentry_getType (s->elements[i] ) ) ) + { + cstring aType; + aType = cstring_beforeChar(ctypeName, '['); + + cur = message ("%s %s %s []", + cQuals, aType, name); + + // cstring_free(ctypeName); + } + else if (ctype_isElips (uentry_getType (s->elements[i] ) ) ) + { + cur = message(" ... "); + } + else + { + cur = message ("%s %s %s", + cQuals, ctypeName, + name ); + } + if (qualList_hasInnerConstQualifier (s->elements[i]->cQuals) ) + { + cur = insertInnerConstQual(cur); + } + } + + if (i == 0) + { + st = message ("%q", cur); + } + else + { + st = message ("%q, %q", + st, cur); + } + } + + return st; + } +} + cstring uentryList_unparseParams (uentryList s) { int i; @@ -229,7 +314,7 @@ uentryList_unparseAbbrev (uentryList p) if (uentryList_size (p) == 0) return cstring_makeLiteral ("void"); - for (i = 0; i < p->nelements && i < PRINTBREADTH; i++) + for (i = 0; i < p->nelements && i < uentryList_abbrevBreadth; i++) { if (first) { @@ -293,7 +378,6 @@ uentryList_lookupRealName (uentryList s, cstring name) uentryList uentryList_copy (uentryList s) { - if (uentryList_isDefined (s)) { uentryList t = (uentryList) dmalloc (sizeof (*t)); @@ -309,14 +393,14 @@ uentryList uentryList_copy (uentryList s) for (i = 0; i < s->nelements; i++) { - t->elements[i] = uentry_copy (s->elements[i]); - } + t->elements[i] = uentry_copy (s->elements[i]); + } } else { t->elements = NULL; } - + return t; } else @@ -348,8 +432,9 @@ uentryList_isVoid (uentryList cl) { if (cl != NULL && cl->nelements == 1) { - return (ctype_isVoid (uentry_getType (cl->elements[0]))); + return (ctype_isVoid (ctype_realType (uentry_getType (cl->elements[0])))); } + return FALSE; } @@ -517,6 +602,10 @@ uentryList_compareFields (uentryList s, uentryList t) if (uc != 0) { + DPRINTF (("Bad compare: %s / %s", + uentry_unparseFull (s->elements [i]), + uentry_unparseFull (t->elements [i]))); + return uc; } } @@ -546,6 +635,7 @@ uentryList_dumpParams (uentryList s) uentryList_elements (s, current) { + DPRINTF (("Dump param: %s", uentry_unparse (current))); st = message ("%q%q,", st, uentry_dumpParam (current)); } end_uentryList_elements; @@ -564,10 +654,12 @@ uentryList_dumpFields (uentryList s) if (!uentry_isVariable (current)) { llassert (uentry_isFunction (current)); + DPRINTF (("Dump field: %s", uentry_unparse (current))); st = message ("%q!%q,", st, uentry_dump (current)); } else { + DPRINTF (("Dump field: %s", uentry_unparse (current))); st = message ("%q%q,", st, uentry_dump (current)); } } end_uentryList_elements; @@ -584,17 +676,17 @@ uentryList_undumpFields (char **s, fileloc loc) { if (**s == '!') { - checkChar (s, '!'); + reader_checkChar (s, '!'); ul = uentryList_add (ul, uentry_undump (ekind_function, loc, s)); } else { ul = uentryList_add (ul, uentry_undump (ekind_variable, loc, s)); } - checkChar (s, ','); + reader_checkChar (s, ','); } - checkChar (s, '}'); + reader_checkChar (s, '}'); return ul; } @@ -621,12 +713,12 @@ uentryList_undump (char **s) uentry_free (ue); } - checkChar (s, ','); + reader_checkChar (s, ','); c = **s; paramno++; } - checkChar (s, ')'); + reader_checkChar (s, ')'); return pn; } @@ -662,7 +754,7 @@ uentryList_size (uentryList s) { if (uentryList_isUndefined (s)) return 0; - if (s->nelements == 1 && ctype_isVoid (uentry_getType (s->elements[0]))) + if (uentryList_isVoid (s)) return 0; return s->nelements; @@ -695,6 +787,26 @@ uentryList_lookupField (uentryList f, cstring name) } else { + uentryList_elements (f, el) + { + if (uentry_isUnnamedVariable (el)) + { + ctype ct = uentry_getType (el); + + if (ctype_isStruct (ct) || ctype_isUnion (ct)) + { + uentryList fields = ctype_getFields (ct); + uentry ue = uentryList_lookupField (fields, name); + + if (uentry_isValid (ue)) + { + return ue; + } + } + } + } + end_uentryList_elements ; + return uentry_undefined; } } @@ -702,6 +814,8 @@ uentryList_lookupField (uentryList f, cstring name) /*@only@*/ uentryList uentryList_mergeFields (/*@only@*/ uentryList f1, /*@only@*/ uentryList f2) { + DPRINTF (("Merge: %s + %s", uentryList_unparse (f1), uentryList_unparse (f2))); + if (uentryList_isUndefined (f1)) { return (f2); @@ -779,6 +893,7 @@ uentryList_showFieldDifference (uentryList p1, uentryList p2) else { /* evs 2000-07-25 was ctype_match, should match uentryList_matchFields */ + if (!ctype_almostEqual (uentry_getType (cp1), uentry_getType (cp2))) { llgenindentmsg @@ -811,6 +926,12 @@ uentryList_showFieldDifference (uentryList p1, uentryList p2) uentryList_unparse (p1), uentryList_unparse (p2))); } +bool +uentryList_equivFields (uentryList p1, uentryList p2) +{ + return (uentryList_compareFields (p1, p2) == 0); +} + bool uentryList_matchFields (uentryList p1, uentryList p2) { @@ -837,13 +958,17 @@ uentryList_matchFields (uentryList p1, uentryList p2) cp1 = p1->elements[index]; cp2 = p2->elements[index]; + /*@i32*/ + /* + ** Should compare uentry's --- need to fix report errors too. + */ + if (!(cstring_equal (uentry_rawName (cp1), uentry_rawName (cp2)) && (ctype_almostEqual (uentry_getType (cp1), uentry_getType (cp2))))) - { /* was ctype_match! */ + { return FALSE; } } return TRUE; } -