Skip to content

Commit

Permalink
- Support for is seq1.
Browse files Browse the repository at this point in the history
-  Addresses #108.
  • Loading branch information
bandurvp committed Oct 9, 2017
1 parent e484cc4 commit ba7ac73
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 25 deletions.
37 changes: 18 additions & 19 deletions c/vdmclib/src/main/VdmBasicTypes.c
Expand Up @@ -214,24 +214,6 @@ bool isNumber(TVP val)
}
}

#ifndef NO_SEQS
TVP isSeq(TVP v)
{
if(v->type == VDM_SEQ)
return newBool(true);
return newBool(false);
}
#endif

#ifndef NO_SETS
TVP isSet(TVP v)
{
if(v->type == VDM_SET)
return newBool(true);
return newBool(false);
}
#endif

TVP isInt(TVP v)
{
if(v->type == VDM_INT)
Expand Down Expand Up @@ -482,7 +464,7 @@ TVP is(TVP v, char ot[])
TVP isres;

/* No nesting inside sequence, set or record. */
if(ot[0] != 'Q' && ot[0] != 'T' && ot[0] != 'P')
if(ot[0] != 'Q' && ot[0] != 'T' && ot[0] != 'P' && ot[0] != 'Z' && ot[0] != 'Y')
{
switch(ot[0])
{
Expand Down Expand Up @@ -537,6 +519,23 @@ TVP is(TVP v, char ot[])
}
}
}
else if(ot[0] == 'Z')
{
if(v->type == VDM_SEQ)
{
if(((struct Collection *)(v->value.ptr))->size > 0)
{
res = true;

for(i = 0; i < ((struct Collection *)(v->value.ptr))->size; i++)
{
isres = is(((struct Collection *)(v->value.ptr))->value[i], &(ot[1]));
res &= isres->value.boolVal;
vdmFree(isres);
}
}
}
}
#endif
#ifndef NO_SETS
else if(ot[0] == 'T')
Expand Down
6 changes: 0 additions & 6 deletions c/vdmclib/src/main/VdmBasicTypes.h
Expand Up @@ -93,12 +93,6 @@ TVP vdmLessOrEqualGC(TVP a, TVP b, TVP *from);
*/
bool isNumber(TVP val);
TVP isInt(TVP val);
#ifndef NO_SEQS
TVP isSeq(TVP val);
#endif
#ifndef NO_SETS
TVP isSet(TVP val);
#endif
TVP isIntGC(TVP val, TVP *from);
TVP isReal(TVP val);
TVP isRealGC(TVP val, TVP *from);
Expand Down
20 changes: 20 additions & 0 deletions c/vdmclib/src/test/Expressions_Tests.cpp
Expand Up @@ -444,6 +444,26 @@ TEST(Expression, isSeqOfInt)
vdmFree(res);
}

TEST(Expression, isSeq1OfIntNegative)
{
char ot[] = "Zi";
TVP res;

res = is(newSeqVar(0), ot);
EXPECT_FALSE(res->value.boolVal);
vdmFree(res);
}

TEST(Expression, isSeq1OfInt)
{
char ot[] = "Zi";
TVP res;

res = is(newSeqVar(2, newInt(1), newInt(-2)), ot);
EXPECT_TRUE(res->value.boolVal);
vdmFree(res);
}

TEST(Expression, isSeqOfSeqOfInt)
{
char ot[] = {'Q', 'Q', 'i'};
Expand Down

0 comments on commit ba7ac73

Please sign in to comment.