X-Git-Url: http://andersk.mit.edu/gitweb/splint.git/blobdiff_plain/616915ddfdcba888735f45cbd9c26c9b5383ee2c..40fabe2650105c5ada4d352bdd15ebbb701c5693:/src/multiVal.c diff --git a/src/multiVal.c b/src/multiVal.c index cf054be..5b9a2b0 100644 --- a/src/multiVal.c +++ b/src/multiVal.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 */ /* ** multiVal.c */ -# include "lclintMacros.nf" +# include "splintMacros.nf" # include "basic.h" /*@only@*/ multiVal multiVal_unknown () @@ -53,8 +53,8 @@ static /*@special@*/ /*@notnull@*/ multiVal multiVal_create (mvkind kind) /*@only@*/ multiVal multiVal_makeChar (char x) { multiVal mv = multiVal_create (MVCHAR); - mv->value.cval = x; - return mv; + mv->value.cval = x; + return mv; } /*@only@*/ multiVal multiVal_makeDouble (double x) @@ -230,13 +230,13 @@ bool multiVal_isString (multiVal m) { case 'i': (*s)++; - return multiVal_makeInt (getInt (s)); + return multiVal_makeInt (reader_getInt (s)); case 'c': (*s)++; - return multiVal_makeChar ((char) getInt (s)); + return multiVal_makeChar ((char) reader_getInt (s)); case 'd': (*s)++; - return multiVal_makeDouble (getDouble (s)); + return multiVal_makeDouble (reader_getDouble (s)); case 's': { cstring st = cstring_undefined; @@ -288,6 +288,95 @@ int multiVal_compare (multiVal m1, multiVal m2) BADEXIT; } +multiVal multiVal_add (multiVal m1, multiVal m2) +{ + if (multiVal_isUndefined (m1) || multiVal_isUndefined (m2) || m1->kind != m2->kind) + { + return multiVal_undefined; + } + + switch (m1->kind) + { + case MVLONG: return (multiVal_makeInt (m1->value.ival + m2->value.ival)); + case MVCHAR: return (multiVal_makeChar ((char) (m1->value.cval + m2->value.cval))); + case MVDOUBLE: return (multiVal_makeDouble (m1->value.fval + m2->value.fval)); + case MVSTRING: return multiVal_undefined; + } + + BADEXIT; +} + +multiVal multiVal_subtract (multiVal m1, multiVal m2) +{ + if (multiVal_isUndefined (m1) || multiVal_isUndefined (m2) || m1->kind != m2->kind) + { + return multiVal_undefined; + } + + switch (m1->kind) + { + case MVLONG: return (multiVal_makeInt (m1->value.ival - m2->value.ival)); + case MVCHAR: return (multiVal_makeChar ((char) (m1->value.cval - m2->value.cval))); + case MVDOUBLE: return (multiVal_makeDouble (m1->value.fval - m2->value.fval)); + case MVSTRING: return multiVal_undefined; + } + + BADEXIT; +} + +multiVal multiVal_multiply (multiVal m1, multiVal m2) +{ + if (multiVal_isUndefined (m1) || multiVal_isUndefined (m2) || m1->kind != m2->kind) + { + return multiVal_undefined; + } + + switch (m1->kind) + { + case MVLONG: return (multiVal_makeInt (m1->value.ival * m2->value.ival)); + case MVCHAR: return (multiVal_makeChar ((char) (m1->value.cval * m2->value.cval))); + case MVDOUBLE: return (multiVal_makeDouble (m1->value.fval * m2->value.fval)); + case MVSTRING: return multiVal_undefined; + } + + BADEXIT; +} + +multiVal multiVal_divide (multiVal m1, multiVal m2) +{ + if (multiVal_isUndefined (m1) || multiVal_isUndefined (m2) || m1->kind != m2->kind) + { + return multiVal_undefined; + } + + switch (m1->kind) + { + case MVLONG: + if (m2->value.ival != 0) + { + return (multiVal_makeInt (m1->value.ival / m2->value.ival)); + } + else + { + return multiVal_undefined; + } + case MVCHAR: + if (m2->value.cval != (char) 0) + { + return (multiVal_makeChar ((char) (m1->value.cval / m2->value.cval))); + } + else + { + return multiVal_undefined; + } + case MVDOUBLE: + return multiVal_undefined; /* Don't attempt to divide floats */ + case MVSTRING: return multiVal_undefined; + } + + BADEXIT; +} + void multiVal_free (/*@only@*/ multiVal m) { if (multiVal_isDefined (m))