X-Git-Url: http://andersk.mit.edu/gitweb/splint.git/blobdiff_plain/6970c11be2c0e175abf98c906a87115836e4f55f..3dabb0778770a6ee8a2af1a104325e2651933ce1:/src/mtContextNode.c diff --git a/src/mtContextNode.c b/src/mtContextNode.c index 22a2926..4cc6e9e 100644 --- a/src/mtContextNode.c +++ b/src/mtContextNode.c @@ -1,6 +1,6 @@ /* -** LCLint - annotation-assisted static program checker -** Copyright (C) 1994-2001 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 */ /* ** mtContextNode.c */ -# include "lclintMacros.nf" +# include "splintMacros.nf" # include "basic.h" static bool mtContextNode_matchesType (mtContextNode, ctype) /*@*/ ; @@ -43,7 +43,7 @@ static /*@observer@*/ cstring mtContextKind_unparse (mtContextKind ck) case MTC_NULL: return cstring_makeLiteralTemp ("null"); } - BADBRANCH; + BADBRANCHRET (cstring_undefined); } static mtContextNode mtContextNode_create (mtContextKind context, ctype ct) @@ -184,7 +184,8 @@ bool mtContextNode_matchesRef (mtContextNode context, sRef sr) bool mtContextNode_matchesRefStrict (mtContextNode context, sRef s) { - if (mtContextNode_matchesRef (context, s)) + if (mtContextNode_isDefined (context) + && mtContextNode_matchesRef (context, s)) { if (ctype_isKnown (context->type) && (ctype_isUnknown (sRef_getType (s)) @@ -204,6 +205,7 @@ bool mtContextNode_matchesRefStrict (mtContextNode context, sRef s) bool mtContextNode_matchesType (mtContextNode context, ctype ct) { DPRINTF (("Context type...")); + llassert (mtContextNode_isDefined (context)); if (!ctype_match (context->type, ct)) { @@ -214,6 +216,12 @@ bool mtContextNode_matchesType (mtContextNode context, ctype ct) } else { + /* evans 2001-08-21 - don't match if only one type is unknown */ + if (ctype_isUnknown (ct) && !ctype_isUnknown (context->type)) + { + return FALSE; + } + DPRINTF (("Type okay: %s / %s", ctype_unparse (context->type), ctype_unparse (ct))); @@ -224,6 +232,8 @@ bool mtContextNode_matchesType (mtContextNode context, ctype ct) cstring mtContextNode_unparse (mtContextNode node) { + llassert (mtContextNode_isDefined (node)); + if (ctype_isKnown (node->type)) { return message ("%s %s", mtContextKind_unparse (node->context), @@ -271,6 +281,65 @@ bool mtContextNode_isNull (mtContextNode n) return (n->context == MTC_NULL); } +void mtContextNode_showRefError (mtContextNode context, sRef sr) +{ + ctype ct; + + llassert (mtContextNode_isDefined (context)); + llassert (!mtContextNode_matchesRef (context, sr)); + + DPRINTF (("Matches context: %s / %s", + mtContextNode_unparse (context), sRef_unparse (sr))); + + switch (context->context) + { + case MTC_ANY: break; /* everything matches */ + case MTC_RESULT: + if (!sRef_isResult (sr)) + { + llgenindentmsgnoloc + (message ("Context is result, doesn't match %q", sRef_unparse (sr))); + return; + } + break; + case MTC_PARAM: + if (!sRef_isResult (sr)) + { + llgenindentmsgnoloc + (message ("Context is parameter, doesn't match %q", sRef_unparse (sr))); + return; + } + break; + case MTC_LITERAL: + DPRINTF (("Literal: %s", sRef_unparse (sr))); + if (!sRef_isConst (sr)) + { + llgenindentmsgnoloc + (message ("Context is literal, doesn't match %q", sRef_unparse (sr))); + return; + } + break; + case MTC_NULL: + case MTC_REFERENCE: + break; + case MTC_CLAUSE: + BADBRANCH; + } + + ct = sRef_getType (sr); + + if (!mtContextNode_matchesType (context, ct)) + { + llgenindentmsgnoloc + (message ("Context type is %s, doesn't match type %s", + ctype_unparse (context->type), + ctype_unparse (ct))); + } + else + { + BADBRANCH; + } +}