Commit 47708334 authored by Sergio Costas's avatar Sergio Costas

Now allows to use the __crust_enable__, __crust_enable_all__ and...

Now allows to use the __crust_enable__, __crust_enable_all__ and __crust_disable__ to control the error messages
parent 74e56d13
This diff is collapsed.
......@@ -89,7 +89,7 @@ char do_verbose = 0;
"__crust_alias__" { return prepare_leaf(0,0.0,CRUSTY_ALIAS); }
"__crust_enable__" { return prepare_leaf(0,0.0,CRUSTY_ENABLE); }
"__crust_disable__" { return prepare_leaf(0,0.0,CRUSTY_DISABLE); }
"__crust_full_disable__" { return prepare_leaf(0,0.0,CRUSTY_FULL_DISABLE); }
"__crust_full_enable__" { return prepare_leaf(0,0.0,CRUSTY_FULL_ENABLE); }
"__crust_debug__" { return prepare_leaf(0,0.0,CRUSTY_DEBUG); }
{L}({L}|{D})* { return prepare_leaf(0,0.0,TYPENAME_IDENTIFIER); }
......
%{
FULL_ENABLE%{
#include <stdio.h>
#include "../crusty.h"
......@@ -35,7 +35,7 @@ void add_type_element(char *);
%token CRUSTY_ALIAS
%token CRUSTY_ENABLE
%token CRUSTY_DISABLE
%token CRUSTY_FULL_DISABLE
%token CRUSTY_FULL_ENABLE
%token CRUSTY_DEBUG
%token VARIABLE_DEFINITION
%token T_NULL
......@@ -725,7 +725,7 @@ block_item
| statement { $$ = $1; }
| CRUSTY_ENABLE { $$ = $1; }
| CRUSTY_DISABLE { $$ = $1; }
| CRUSTY_FULL_DISABLE { $$ = $1; }
| CRUSTY_FULL_ENABLE { $$ = $1; }
| CRUSTY_DEBUG { $$ = $1; }
;
......
......@@ -88,7 +88,7 @@ class Test(unittest.TestCase):
self._generic_test("unitest/test6.c",[ (crusty.crusty.MSG_CRITICAL,"Expected a __crust_t__ variable at parameter {:d} when calling function '{:s}' at line {:d}, but passed non __crust_t__ variable",1,"function",6) ])
def testPassedCrustyToNonCrusty(self):
self._generic_test("unitest/test7.c",[ (crusty.crusty.MSG_CRITICAL,"Expected a non __crust_t__ variable at parameter {:d} when calling function '{:s}' at line {:d}, but passed a __crust_t__ variable",1,"function",10) ])
self._generic_test("unitest/test7.c",[ (crusty.crusty.MSG_CRITICAL,"Expected a non __crust_t__ variable at parameter {:d} when calling function '{:s}' at line {:d}, but passed a __crust_t__ variable",1,"function",6) ])
def testPassedOtherToCrusty(self):
self._generic_test("unitest/test8.c",[ (crusty.crusty.MSG_CRITICAL,"Expected a __crust_t__ variable at parameter {:d} when calling function '{:s}' at line {:d}",1,"function",5) ])
......@@ -151,7 +151,7 @@ class Test(unittest.TestCase):
self._generic_test("unitest/test27.c",[ (crusty.crusty.MSG_CRITICAL,"Assigning a non-crust value to the crust variable '{:s}' at line {:d}","param",5) ])
def testCrustRetVal(self):
self._generic_test("unitest/test28.c",[ (crusty.crusty.MSG_ERROR,"Calling the function '{:s}' at line {:d}, but ignoring the crust-type return value","function",9) ])
self._generic_test("unitest/test28.c",[ (crusty.crusty.MSG_ERROR,"Calling the function '{:s}' at line {:d}, but ignoring the crust-type return value","function",5) ])
def testUseUninitialized2(self):
self._generic_test("unitest/test29.c",[ (crusty.crusty.MSG_ERROR,"Parameter {:d} when calling function '{:s}' at line {:d} isn't initialized",1,"function",5) ])
......@@ -220,7 +220,7 @@ class Test(unittest.TestCase):
self._check_var_status(lib,"var2",crusty.crusty.STATUS_NULL)
def testPassBorrowToNonBorrow(self):
self._generic_test("unitest/test50.c",[ (crusty.crusty.MSG_CRITICAL,"Parameter '{:s}' at position {:d} when calling function '{:s}' at line {:d} is borrowed, but is used as a non-borrow parameter",'param',1,"test_function",10) ])
self._generic_test("unitest/test50.c",[ (crusty.crusty.MSG_CRITICAL,"Parameter '{:s}' at position {:d} when calling function '{:s}' at line {:d} is borrowed, but is used as a non-borrow parameter",'param',1,"test_function",8) ])
def testPassBorrowToBorrow(self):
self._all_fine_test("unitest/test51.c")
......@@ -277,10 +277,10 @@ class Test(unittest.TestCase):
self._generic_test("unitest/test68.c",[(crusty.crusty.MSG_ERROR,"Overwritting a borrowed block ('{:s}' at line {:d}) with a new block is not allowed", "param", 7), (crusty.crusty.MSG_ERROR,"Assignment to '{:s}' at line {:d}, which was already assigned at line {:d}", "param", 7, 5)])
def testAssignmentFromBorrowBlock(self):
self._generic_test("unitest/test69.c",[ (crusty.crusty.MSG_ERROR,"Assigning a borrowed block into a local variable is not allowed (assigning '{:s}' at line {:d})","param",13) ])
self._generic_test("unitest/test69.c",[ (crusty.crusty.MSG_ERROR,"Assigning a borrowed block into a local variable is not allowed (assigning '{:s}' at line {:d})","param",9) ])
def testAssignmentFromBorrowBlock2(self):
self._generic_test("unitest/test70.c",[ (crusty.crusty.MSG_ERROR,"Assigning a borrowed block into a local variable is not allowed (assigning '{:s}' at line {:d})","param",13) ])
self._generic_test("unitest/test70.c",[ (crusty.crusty.MSG_ERROR,"Assigning a borrowed block into a local variable is not allowed (assigning '{:s}' at line {:d})","param",9) ])
def testAssignmentToAndFromMemberOfBorrowBlock(self):
self._all_fine_test("unitest/test71.c")
......
__crust_t__ int function() { // ERROR: retval is crust, but it is not a pointer
// empty function
}
......@@ -3,5 +3,5 @@ typedef __crust_t__ unsigned char *crust_t;
void function(crust_t param1) {
crust_t param4;
int retval = (param4 == NULL) ? 1 : 0; // ERROR: conditional depends on an uninitialized variable
function(param1); // a trick to free param1 and trigger only one error
__crust_disable__ // added here to ensure only one error per unitest
}
......@@ -4,5 +4,5 @@ int function(crust_t param1) {
crust_t param4 = NULL;
int retval = function(param4);
int retval = (param4 == NULL) ? 1 : 0; // ERROR: condition depends on a freed variable
function(param1); // a trick to free param1 and trigger only one error
__crust_disable__ // added here to ensure only one error per unitest
}
......@@ -3,5 +3,5 @@ typedef __crust_t__ int * crust_t;
int function(crust_t param1) {
crust_t param4 = param1;
crust_t param5 = param1; // ERROR: assigning a previously freed variable (due to assign in line 4)
function(param4); // a trick to free param4 and trigger only one error
__crust_disable__ // added here to ensure only one error per unitest
}
......@@ -4,6 +4,5 @@ int function(crust_t param3) {
int v = 5;
crust_t param = (crust_t) v; // This is legal
function(param3); // a trick to free param3 and trigger only one error
function(param); // a trick to free param and trigger only one error
__crust_disable__ // added here to ensure only one error per unitest
}
......@@ -3,6 +3,5 @@ typedef __crust_t__ unsigned char *crust_t;
int function(crust_t param1) {
crust_t param = 5; // ERROR: assigning a constant (non-crust) to a crust variable
function(param1); // a trick to free param1 and trigger only one error
function(param); // a trick to free param and trigger only one error
__crust_disable__ // added here to ensure only one error per unitest}
}
typedef __crust_t__ unsigned char *crust_t;
void function2(crust_t param3) {
function2(param3); // a trick to free param3 and trigger only one error
}
crust_t function(crust_t param3) {
function(NULL); // ERROR: the function returns a crust_t pointer, but it isn't stored
function2(param3); // a trick to free param3 and trigger only one error
__crust_disable__ // added here to ensure only one error per unitest
}
......@@ -3,5 +3,5 @@ typedef __crust_t__ unsigned char *crust_t;
int function(crust_t param3) {
crust_t param4;
function(param4); // ERROR: calling a function with an uninitialized parameter
function(param3); // a trick to free param3 and trigger only one error
__crust_disable__ // added here to ensure only one error per unitest
}
......@@ -3,5 +3,5 @@ typedef __crust_t__ unsigned char *crust_t;
int function(crust_t param1, crust_t param2) {
crust_t param3 = param1;
param3 = param2; // ERROR: param3 is overwriten by another variable without being NULL
function(param3,NULL);
__crust_disable__ // added here to ensure only one error per unitest
}
......@@ -4,5 +4,5 @@ int function(crust_t param3) {
int *param = 1;
function(param); // ERROR: calling a function passing a non-crust value as a crust parameter
function(param3); // a trick to free param3 and trigger only one error
__crust_disable__ // added here to ensure only one error per unitest
}
......@@ -3,5 +3,5 @@ typedef __crust_t__ unsigned char *crust_t;
int function(crust_t param3) {
function(2); // ERROR: calling a function passing a constant (non-crust) value as a crust parameter
function(param3); // a trick to free param3 and trigger only one error
__crust_disable__ // added here to ensure only one error per unitest
}
......@@ -4,7 +4,5 @@ void main(crust_t param1) {
crust_t a,b;
a = b = 5; // ERROR: assigning a non-crust value to two crust variables
main(param1); // a trick to free param1 and trigger only one error
main(a); // a trick to free a and trigger only one error
main(b); // a trick to free b and trigger only one error
__crust_disable__ // added here to ensure only one error per unitest
}
......@@ -6,6 +6,5 @@ struct {
int function(crust_t param3) {
crust_t param4 = test.value; // this is legal
function(param3); // a trick to free param3 and trigger only one error
function(param4); // a trick to free param4 and trigger only one error
__crust_disable__ // added here to ensure only one error per unitest
}
......@@ -6,6 +6,5 @@ struct {
int function(crust_t param3) {
crust_t param4 = test; // ERROR: assigning a non-crust variable into a crust variable
function(param3); // a trick to free param3 and trigger only one error
function(param4); // a trick to free param4 and trigger only one error
__crust_disable__ // added here to ensure only one error per unitest
}
......@@ -4,6 +4,5 @@ crust_t test[5];
int function(crust_t param1) {
crust_t param4 = test[1]; // this is legal
function(param1); // a trick to free param1 and trigger only one error
function(param4); // a trick to free param4 and trigger only one error
__crust_disable__ // added here to ensure only one error per unitest
}
......@@ -4,6 +4,5 @@ crust_t test[5];
int function(crust_t param1) {
crust_t param4 = test; // ERROR: it is an array, not a crust_t element
function(param1); // a trick to free param1 and trigger only one error
function(param4); // a trick to free param4 and trigger only one error
__crust_disable__ // added here to ensure only one error per unitest
}
......@@ -3,5 +3,5 @@ typedef __crust_t__ unsigned char *crust_t;
int function(crust_t param3) {
crust_t param4;
int retval = function(param4); // ERROR: param4 is used before being assigned
function(param3); // a trick to free param3 and trigger only one error
__crust_disable__ // added here to ensure only one error per unitest
}
......@@ -6,6 +6,5 @@ struct {
int function(crust_t param3) {
crust_t param4 = test->value; // this is legal
function(param3); // a trick to free param3 and trigger only one error
function(param4); // a trick to free param4 and trigger only one error
__crust_disable__ // added here to ensure only one error per unitest
}
......@@ -7,9 +7,7 @@ void main(crust_t param) {
crust_t var2 = (crust_t) 5;
if (param == NULL) {
param = var2;
} else {
main(var2); // a trick to free var2 and trigger only one error
param = var2; // this is legal (assigning an object to a NULL variable)
}
main(param); // a trick to free param and trigger only one error
__crust_disable__ // added here to ensure only one error per unitest
}
......@@ -8,6 +8,6 @@ void main(crust_t param) {
if (param != NULL) {
main(param);
}
param = var2;
main(param); // a trick to free param and trigger only one error
param = var2; // if param was NULL, var2 can be assigned; if it wasn't, "main(param)" was called, so now it is FREED and can be assigned
__crust_disable__ // added here to ensure only one error per unitest
}
......@@ -7,9 +7,9 @@ void main(crust_t param) {
crust_t var2 = (crust_t) 5;
if (param != NULL) {
main(param);
main(var2); // a trick to free var2 and trigger only one error
} else {
param = var2;
main(param);
main(param); // all is legal
}
__crust_disable__ // added here to ensure only one error per unitest
}
......@@ -2,16 +2,11 @@ typedef __crust_t__ unsigned char *crust_t;
#define NULL ((void *)0)
void function(crust_t param) {
function(param); // a trick to free param and trigger only one error
}
crust_t main(crust_t __crust_recycle__ param) {
crust_t var2 = (crust_t) 5;
crust_t var3;
var3 = main(var2); // This is legal
__crust_debug__
function(param); // a trick to free param and trigger only one error
function(var3); // a trick to free var3 and trigger only one error
__crust_disable__ // added here to ensure only one error per unitest
}
typedef __crust_t__ unsigned char *crust_t;
#define NULL ((void *)0)
int function(crust_t param1) {
function(param1); // a trick to free param1 and trigger only one error
}
void main(crust_t __crust_borrow__ param) {
crust_t var2 = (crust_t) 5;
main(var2); // This is legal
__crust_debug__
function(var2); // a trick to free var2 and trigger only one error
__crust_disable__ // added here to ensure only one error per unitest
}
......@@ -2,9 +2,7 @@ typedef __crust_t__ unsigned char *crust_t;
#define NULL ((void *)0)
void test_function(crust_t param) {
test_function(param); // a trick to free param and trigger only one error
}
void test_function(crust_t param);
void main(crust_t __crust_borrow__ param) {
test_function(param); // ERROR: can't pass a borrowed variable as a non-borrow parameter
......
......@@ -7,5 +7,5 @@ void test_function(crust_t __crust_borrow__ param) {
void main(crust_t __crust_borrow__ param) {
void (*prueba)(crust_t __crust_borrow__);
prueba = test_function;
prueba = test_function; // this is legal
}
......@@ -7,5 +7,5 @@ void test_function(crust_t __crust_borrow__ param) {
void main(crust_t __crust_borrow__ param2) {
void (*test2)(crust_t param3);
test2 = test_function;
test2 = test_function; // this is legal
}
......@@ -8,5 +8,5 @@ void test_function(crust_t __crust_borrow__ param) {
void (*test2)(crust_t param);
void main(crust_t __crust_borrow__ param) {
test2 = test_function;
test2 = test_function; // this is legal
}
......@@ -7,5 +7,5 @@ void test_function(crust_t __crust_borrow__ param) {
void main(crust_t __crust_borrow__ param) {
void (*test2)(crust_t param);
test_function = test2;
test_function = test2; // ERROR: assigning a value to a function name
}
......@@ -9,5 +9,5 @@ void main() {
if (a->b >= 1)
printf("1\n");
else
printf("no 1\n");
printf("no 1\n"); // all is legal
}
......@@ -11,5 +11,5 @@ void main() {
else if (a->b >= 2)
printf("2\n");
else
printf("no 1,2\n");
printf("no 1,2\n"); // all is legal
}
......@@ -12,7 +12,7 @@ void main() {
if (a->b >= 2) {
printf("2\n");
} else {
printf("no 1,2\n");
printf("no 1,2\n"); // all is legal
}
}
}
......@@ -4,5 +4,5 @@ int function(crust_t param3) {
int *param = 1;
int retval = function(param); // ERROR: passed non-crust variable as a crust parameter
function(param3); // a trick to free param3 and trigger only one error
__crust_disable__ // added here to ensure only one error per unitest
}
......@@ -9,7 +9,7 @@ void main(crust_t param) {
param = var2;
main(param);
} else {
main(param);
main(var2); // a trick to free var2 and trigger only one error
main(param); // all is legal
}
__crust_disable__ // added here to ensure only one error per unitest
}
......@@ -6,9 +6,7 @@ void main(crust_t param) {
crust_t var2 = (crust_t) 5;
if (!(param == NULL)) {
param = var2;
} else {
main(var2); // a trick to free var2 and trigger only one error
param = var2; // ERROR: param is not NULL
}
main(param); // a trick to free param and trigger only one error
__crust_disable__ // added here to ensure only one error per unitest
}
......@@ -4,5 +4,5 @@ typedef __crust_t__ unsigned char *crust_t;
void main(crust_t param) {
main(NULL);
// ERROR: param is not managed at the end of the block
// ERROR: 'param' is not managed at the end of the non-empty block
}
......@@ -3,5 +3,5 @@ typedef __crust_t__ unsigned char *crust_t;
#define NULL ((void *)0)
void main(crust_t param) {
// ERROR: param is not managed at the end of the block
// ERROR: 'param' is not managed at the end of the empty block
}
......@@ -11,5 +11,5 @@ void main(crust_t param) {
if (var2 == NULL) {
return;
}
main(var2);
main(var2); // 'var2' has been managed when it is not NULL. All this is legal
}
......@@ -4,5 +4,6 @@ typedef __crust_t__ unsigned char *crust_t;
void main(crust_t __crust_borrow__ param) {
param = NULL;
param = NULL; // ERROR: param already has a value
// ERROR: a borrowed parameter can't be overwritten
}
......@@ -2,14 +2,10 @@ typedef __crust_t__ unsigned char *crust_t;
#define NULL ((void *)0)
void function(crust_t param) {
function(param); // a trick to free param and trigger only one error
}
void main(crust_t __crust_borrow__ param) {
crust_t var2;
var2 = param;
function(var2); // a trick to free var2 and trigger only one error
var2 = param; // ERROR: a borrowed parameter can't be assigned to another crust variable
__crust_disable__ // added here to ensure only one error per unitest
}
typedef __crust_t__ unsigned char *crust_t;
void function2(crust_t param3) {
function2(param3); // a trick to free param3 and trigger only one error
}
crust_t function(int param3) {
crust_t param = NULL;
crust_t retval = function(param); // ERROR: passed a crust variable to a non-crust param
function2(retval); // a trick to free retval and trigger only one error
__crust_disable__ // added here to ensure only one error per unitest
}
......@@ -2,14 +2,10 @@ typedef __crust_t__ unsigned char *crust_t;
#define NULL ((void *)0)
void function(crust_t param) {
function(param); // a trick to free param and trigger only one error
}
void main(crust_t __crust_borrow__ param) {
crust_t var2;
var2 = 1 ? param : NULL;
function(var2); // a trick to free var2 and trigger only one error
var2 = 1 ? param : NULL; // Assigning a borrowed block to a local variable is not allowed
__crust_disable__ // added here to ensure only one error per unitest
}
......@@ -7,5 +7,5 @@ typedef __crust_t__ struct {
void main(crust_t __crust_borrow__ param) {
int var2 = param->element;
param->element = var2;
param->element = var2; // All is legal
}
......@@ -3,5 +3,5 @@ typedef __crust_t__ unsigned char *crust_t;
int function(crust_t param3) {
int retval = function(2); // ERROR: passed a constant (non-crust) as a crust parameter
function(param3); // a trick to free param3 and trigger only one error
__crust_disable__ // added here to ensure only one error per unitest
}
......@@ -3,5 +3,5 @@ typedef __crust_t__ unsigned char *crust_t;
int function(crust_t param3) {
int retval = function(3,5); // ERROR: incorrect number of parameters
function(param3); // a trick to free param3 and trigger only one error
__crust_disable__ // added here to ensure only one error per unitest
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment