コード例 #1
0
RC freeExpr(Expr *expr) {
	switch (expr->type) {
	case EXPR_OP: {
		Operator *op = expr->expr.op;
		switch (op->type) {
		case OP_BOOL_NOT:
			freeExpr(op->args[0]);
			break;
		default:
			freeExpr(op->args[0]);
			freeExpr(op->args[1]);
			break;
		}
		free(op->args);
		free(op);
	}
	break;
	case EXPR_CONST:
		freeVal(expr->expr.cons);
		break;
	case EXPR_ATTRREF:
		break;
	}
	free(expr);

	return RC_OK;
}
コード例 #2
0
ファイル: memory.c プロジェクト: JackHolland/Tap
/*! A helper function for freeExpr and freeExprNR
    @param expr     the expression to free from memory
    @param next     whether to free the next expression as well as the given one
    @return         0
*/
static bool freeExpr_ (expression* expr, bool next) {
    if (expr != NULL) { // if the expression isn't null
        exprvals ev = expr->ev;
        switch (expr->type) { // depending on the expression's type
            case TYPE_EXP:
                freeExpr(ev.expval); // recursively call this function with the expression's child expression
                break;
            case TYPE_LAZ:
                freeLaz(ev.lazval);
                break;
            case TYPE_STR:
                freeStr(ev.strval);
                break;
            case TYPE_ARR:
                freeArr(ev.arrval);
                break;
            case TYPE_OBJ:
            	freeObj(ev.objval);
            case TYPE_FUN:
                freeFun(ev.funval);
                break;
        }
        if (next) { // if the next expression should be freed
            freeExpr(expr->next); // recursively call this function with the expression's next expression
        }
        free(expr); // free the expression itself
    }
    
    return 0;
}
コード例 #3
0
ファイル: memory.c プロジェクト: JackHolland/Tap
/*! Frees from memory the given array and its content
    @param le       the lazy expression to free from memory
    @return         0
*/
bool freeLaz (tap_laz* laz) {
	freeExpr(laz->expval);
	exprstack* es1 = laz->refs;
	exprstack* es2;
	while (es1 != NULL) {
		es2 = es1->next;
		freeExpr(es1->expr);
		es1 = es2;
	}
	free(laz);
	
	return 0;
}
コード例 #4
0
ファイル: syntax.c プロジェクト: ColeJackes/pcp
/* evaluate constant expression */
static void
evalConst(Expr *x)
{
    if ((x->op < ACT_SHELL) &&
	(x->arg1->op == NOP) &&
	((x->arg2 == NULL) || (x->arg2->op == NOP))) {
	(x->eval)(x);
	x->op = NOP;
	x->eval = NULL;
	freeExpr(x->arg1);  x->arg1 = NULL;
	freeExpr(x->arg2);  x->arg2 = NULL;
    }
}
コード例 #5
0
ファイル: memory.c プロジェクト: JackHolland/Tap
/*! Frees from memory the given argument
	@param arg		the argument to free from memory
	@return			0
*/
bool freeArg (argument* arg) {
	freeStr(arg->name);
	freeTypelist(arg->types);
	freeExpr(arg->initial);
	free(arg);
	
	return 0;
}
コード例 #6
0
ファイル: memory.c プロジェクト: JackHolland/Tap
/*! Frees from memory the given array and its content
    @param arr      the array to free from memory
    @return         0
*/
bool freeArr (array* arr) {
	int i;
	for (i = arr->start; i <= arr->end; i++) {
		freeExpr(arr->content[i]);
	}
	free(arr);
	
	return 0;
}
コード例 #7
0
ファイル: memory.c プロジェクト: JackHolland/Tap
/*! Frees from memory the given stack of expressions
	@param es		the stack of expressions
	@return			0
*/
bool freeExprstack (exprstack* es) {
	exprstack* next_es;
	while (es != NULL) {
		next_es = es->next;
		freeExpr(es->expr);
		free(es);
		es = next_es;
	}
	
	return 0;
}
コード例 #8
0
ファイル: memory.c プロジェクト: JackHolland/Tap
/*! Frees from memory the given property and its content
    @param prop     the property to free from memory
    @return         0
*/
bool freeProp (property* prop) {
	free(prop->name);
	freeTypelist(prop->types);
	freeExpr(prop->value);
	if (prop->next != NULL) {
		freeProp(prop->next);
	}
	free(prop);
	
	return 0;
}
コード例 #9
0
ファイル: veritypes.c プロジェクト: jwodder/Verity
void freeExpr(expr* ex) {
 if (!ex) return;
 int arity = 2;
 switch (ex->oper) {
  case 0: ex->sym->refQty--; break;
  case ':': ex->sym->refQty--;
  case NOT: arity = 1;
  default: for (int i=0; i<arity; i++) freeExpr(ex->args[i]);
 }
 free(ex);
}
コード例 #10
0
ファイル: syntax.c プロジェクト: ColeJackes/pcp
/* statement */
Symbol
statement(char *name, Expr *x)
{
    Symbol   s;

    /* error guard */
    if (x == NULL) return NULL;

    /* if name not given, make one up */
    if (name == NULL) name = nameGen();

    /* the parsed object is a rule (expression to evaluate) */
    if (x->op != NOP) {
	if (symLookup(&rules, name)) {
	    synerr();
	    fprintf(stderr, "rule \"%s\" multiply defined\n", name);
	    freeExpr(x);
	    return NULL;
	}
	else {
	    if (errs == 0) {
		postExpr(x);
		s = symIntern(&rules, name);
	    }
	    else return NULL;
	}
    }

    /* the parsed object is a non-rule */
    else {
	if ( (s = symLookup(&vars, name)) )
	    freeExpr(symValue(s));
	else
	    s = symIntern(&vars, name);
    }

    symValue(s) = x;
    return s;
}
コード例 #11
0
ファイル: dstruct.c プロジェクト: ColeJackes/pcp
void
freeExpr(Expr *x)
{
    Metric	*m;
    int		i;

    if (x) {
	if (x->arg1 && x->arg1->parent == x)
	    freeExpr(x->arg1);
	if (x->arg2 && x->arg2->parent == x)
	    freeExpr(x->arg2);
	if (x->metrics && x->op == CND_FETCH) {
	    for (m = x->metrics, i = 0; i < x->hdom; m++, i++)
		freeMetric(m);
	    /*
	     * x->metrics allocated in a block, one element per host, so
	     * free as one after all other freeing has been done.
	     */
	    free(x->metrics);
	}
	if (x->ring) free(x->ring);
	free(x);
    }
}
コード例 #12
0
ファイル: veritypes.c プロジェクト: jwodder/Verity
void clearLists(void) {
 for (expr* ex = statements; ex != NULL; ) {
  expr* next = ex->next;
  freeExpr(ex);
  ex = next;
 }
 statements = NULL;
 stmntQty = 0;
 for (symbol* s = symTbl; s != NULL; ) {
  symbol* next = s->next;
  free(s);
  s = next;
 }
 symTbl = NULL;
 symQty = 0;
}
コード例 #13
0
ファイル: memory.c プロジェクト: JackHolland/Tap
/*! Frees from memory the given function and its content
    @param fun      the function to free from memory
    @return         0
*/
bool freeFun (tap_fun* fun) {
	freeExpr(fun->body);
    int numargs;
    if (fun->maxargs == ARGLEN_INF) {
        numargs = fun->minargs;
    } else {
        numargs = fun->maxargs;
    }
    int i;
    for (i = 0; i < numargs; ++i) {
        freeArg(fun->args[i]);
    }
    free(fun);
    
    return 0;
}
コード例 #14
0
ファイル: main.c プロジェクト: JackHolland/Tap
/*! Main function run from the command line
    @param argc     argument count (the number of arguments given)
    @param argv     argument values (the array of arguments given)
    @return         the return code of the program (EXIT_SUCCESS for a successful output, another code for an error)
*/
int main (int argc, char* argv[]) {
    if (argc >= 2) {
        initializeGlobals();
        expression* parsed = parse(argv[1]);
        expression* evaluated;
        if (errors == NULL) {
            evaluated = evaluate(parsed);
        } else {
            evaluated = newExpressionOfType(TYPE_NIL);
        }
        char* printed = printExpression(evaluated);
        char* errortext = printErrors();
        printf("%s\n%s", printed, errortext);
        free(printed);
        freeExpr(evaluated);
        freeGlobals();
        return EXIT_SUCCESS;
    } else {
        return EXIT_NO_ARGS;
    }
}
コード例 #15
0
void testScans (void)
{
  RM_TableData *table = (RM_TableData *) malloc(sizeof(RM_TableData));
  TestRecord inserts[] = { 
    {1, "aaaa", 3}, 
    {2, "bbbb", 2},
    {3, "cccc", 1},
    {4, "dddd", 3},
    {5, "eeee", 5},
    {6, "ffff", 1},
    {7, "gggg", 3},
    {8, "hhhh", 3},
    {9, "iiii", 2},
    {10, "jjjj", 5},
  };
  TestRecord scanOneResult[] = { 
    {3, "cccc", 1},
    {6, "ffff", 1},
  };
  bool foundScan[] = {
    FALSE,
    FALSE
  };
  int numInserts = 10, scanSizeOne = 2, i;
  Record *r;
  RID *rids;
  Schema *schema;
  RM_ScanHandle *sc = (RM_ScanHandle *) malloc(sizeof(RM_ScanHandle));
  Expr *sel, *left, *right;
  int rc;

  testName = "test creating a new table and inserting tuples";
  schema = testSchema();
  rids = (RID *) malloc(sizeof(RID) * numInserts);
  
  TEST_CHECK(initRecordManager(NULL));
  TEST_CHECK(createTable("test_table_r",schema));
  TEST_CHECK(openTable(table, "test_table_r"));
  
  // insert rows into table
  for(i = 0; i < numInserts; i++)
  {
      r = fromTestRecord(schema, inserts[i]);
      TEST_CHECK(insertRecord(table,r)); 
      rids[i] = r->id;
  }

  TEST_CHECK(closeTable(table));
  TEST_CHECK(openTable(table, "test_table_r"));

  // run some scans
  MAKE_CONS(left, stringToValue("i1"));
  MAKE_ATTRREF(right, 2);
  MAKE_BINOP_EXPR(sel, left, right, OP_COMP_EQUAL);

  TEST_CHECK(startScan(table, sc, sel));
  while((rc = next(sc, r)) == RC_OK)
  {
      for(i = 0; i < scanSizeOne; i++)
      {
          if (memcmp(fromTestRecord(schema, scanOneResult[i])->data,r->data,getRecordSize(schema)) == 0)
              foundScan[i] = TRUE;
      }
  }
  if (rc != RC_NO_TUPLES)
    TEST_CHECK(rc);
  TEST_CHECK(closeScan(sc));
  for(i = 0; i < scanSizeOne; i++)
    ASSERT_TRUE(foundScan[i], "check for scan result");
  
  // clean up
  TEST_CHECK(closeTable(table));
  TEST_CHECK(deleteTable("test_table_r"));
  TEST_CHECK(shutdownRecordManager());

  free(table);
  free(sc);
  freeExpr(sel);
  TEST_DONE();
}
コード例 #16
0
void testScansTwo (void)
{
  RM_TableData *table = (RM_TableData *) malloc(sizeof(RM_TableData));
  TestRecord inserts[] = { 
    {1, "aaaa", 3}, 
    {2, "bbbb", 2},
    {3, "cccc", 1},
    {4, "dddd", 3},
    {5, "eeee", 5},
    {6, "ffff", 1},
    {7, "gggg", 3},
    {8, "hhhh", 3},
    {9, "iiii", 2},
    {10, "jjjj", 5},
  };
  bool foundScan[] = {
    FALSE,
    FALSE,
    FALSE,
    FALSE,
    FALSE,
    FALSE,
    FALSE,
    FALSE,
    FALSE,
    FALSE
  };
  int numInserts = 10, i;
  Record *r;
  RID *rids;
  Schema *schema;
  RM_ScanHandle *sc = (RM_ScanHandle *) malloc(sizeof(RM_ScanHandle));
  Expr *sel, *left, *right, *first, *se;
  int rc;

  testName = "test creating a new table and inserting tuples";
  schema = testSchema();
  rids = (RID *) malloc(sizeof(RID) * numInserts);
  
  TEST_CHECK(initRecordManager(NULL));
  TEST_CHECK(createTable("test_table_r",schema));
  TEST_CHECK(openTable(table, "test_table_r"));
  
  // insert rows into table
  for(i = 0; i < numInserts; i++)
  {
    r = fromTestRecord(schema, inserts[i]);
    TEST_CHECK(insertRecord(table,r)); 
    rids[i] = r->id;
  }

  TEST_CHECK(closeTable(table));
  TEST_CHECK(openTable(table, "test_table_r"));

  // Select 1 record with INT in condition a=2.
  MAKE_CONS(left, stringToValue("i2"));
  MAKE_ATTRREF(right, 0);
  MAKE_BINOP_EXPR(sel, left, right, OP_COMP_EQUAL);
  createRecord(&r, schema);
  TEST_CHECK(startScan(table, sc, sel));
  while((rc = next(sc, r)) == RC_OK)
  {
     ASSERT_EQUALS_RECORDS(fromTestRecord(schema, inserts[1]), r, schema, "compare records");
  }
  if (rc != RC_NO_TUPLES)
    TEST_CHECK(rc);
  TEST_CHECK(closeScan(sc));
  
  // Select 1 record with STRING in condition b='ffff'.
  MAKE_CONS(left, stringToValue("sffff"));
  MAKE_ATTRREF(right, 1);
  MAKE_BINOP_EXPR(sel, left, right, OP_COMP_EQUAL);
  createRecord(&r, schema);
  TEST_CHECK(startScan(table, sc, sel));
  while((rc = next(sc, r)) == RC_OK)
  {
     ASSERT_EQUALS_RECORDS(fromTestRecord(schema, inserts[5]), r, schema, "compare records");
     serializeRecord(r, schema);
  }
  if (rc != RC_NO_TUPLES)
    TEST_CHECK(rc);
  TEST_CHECK(closeScan(sc));
  
  // Select all records, with condition being false
  MAKE_CONS(left, stringToValue("i4"));
  MAKE_ATTRREF(right, 2);
  MAKE_BINOP_EXPR(first, right, left, OP_COMP_SMALLER);
  MAKE_UNOP_EXPR(se, first, OP_BOOL_NOT);
  TEST_CHECK(startScan(table, sc, se));
    while((rc = next(sc, r)) == RC_OK)
    {
     serializeRecord(r, schema);
     for(i = 0; i < numInserts; i++)
     {
       if (memcmp(fromTestRecord(schema, inserts[i])->data,r->data,getRecordSize(schema)) == 0)
	     foundScan[i] = TRUE;
     }
    }
  if (rc != RC_NO_TUPLES)
    TEST_CHECK(rc);
  TEST_CHECK(closeScan(sc));
  
  ASSERT_TRUE(!foundScan[0], "not greater than four");
  ASSERT_TRUE(foundScan[4], "greater than four");
  ASSERT_TRUE(foundScan[9], "greater than four");

  // clean up
  TEST_CHECK(closeTable(table));
  TEST_CHECK(deleteTable("test_table_r"));
  TEST_CHECK(shutdownRecordManager());

  freeRecord(r);
  free(table);
  free(sc);
  freeExpr(sel);
  TEST_DONE();
}
コード例 #17
0
ファイル: syntax.c プロジェクト: ColeJackes/pcp
/* aggregation/quantification operator expression */
Expr *
domainExpr(int op, int dom, Expr *arg)
{
    Expr    *x;
    int	    hdom;
    int	    idom;
    int	    tdom;

    /* error guard */
    if (arg == NULL) return NULL;

    hdom = arg->hdom;
    idom = arg->e_idom;
    tdom = arg->tdom;

    switch (dom) {
    case HOST_DOM:
        if (hdom == -1) {
            synerr();
            fprintf(stderr, "no host domain\n");
	    freeExpr(arg);
	    return NULL;
        }
        hdom = -1;
	idom = -1;
	dom = 0;
        break;
    case INST_DOM:
#if 0
	/*
	 * I believe this test is no longer correct ... the instance
	 * domain may be unobtainable at this point, or may change
	 * later so checking at the syntactic level is not helpful
	 */
        if (idom == -1) {
            synerr();
            fprintf(stderr, "no instance domain\n");
	    freeExpr(arg);
	    return NULL;
        }
#endif
        idom = -1;
	dom = 1;
        break;
    case TIME_DOM:
        if (tdom == -1) {
            synerr();
            fprintf(stderr, "no time domain\n");
	    freeExpr(arg);
	    return NULL;
        }
        tdom = -1;
	dom = 2;
    }

    if (op == CND_COUNT_HOST) {
	x = newExpr(op + dom, arg, NULL, hdom, idom, tdom, abs(tdom), PM_SEM_INSTANT);
	newRingBfr(x);
	x->units = countUnits;
    }
    else {
	x = newExpr(op + dom, arg, NULL, hdom, idom, tdom, abs(tdom), arg->sem);
	newRingBfr(x);
    }

    findEval(x);
    return x;
}