ScAddr const & resolveAddr(ScTemplateItemValue const & value) const
    {
        switch (value.mItemType)
        {
        case ScTemplateItemValue::VT_Addr:
            return value.mAddrValue;

        case ScTemplateItemValue::VT_Replace:
        {
            auto it = mTemplate.mReplacements.find(value.mReplacementName);
            check_expr(it != mTemplate.mReplacements.end());
            check_expr(it->second < mResultAddrs.size());
            return mResultAddrs[it->second];
        }

		case ScTemplateItemValue::VT_Type:
		{
			if (!value.mReplacementName.empty())
			{
				auto it = mTemplate.mReplacements.find(value.mReplacementName);
				check_expr(it != mTemplate.mReplacements.end());
				check_expr(it->second < mResultAddrs.size());
				return mResultAddrs[it->second];
			}
			break;
		}
        
        default:
            break;
        };

        static ScAddr empty;
        return empty;
    }
Exemplo n.º 2
0
int check_ternary_op(is_ternary_op* node)
{
	char *typeA, *typeB;
	int errors = 0;

	errors += check_expr(node->if_expr);
	if (errors == 0 && !type_native_assign_able(t_type_native_bool, node->if_expr->s_type))
	{
		errors++;
		typeA = string_type_decl(node->if_expr->s_type);

		pretty_error(node->line, "ternary conditional is not boolean (is of type %s)", typeA);

		free(typeA);
	}

	errors += check_expr(node->then_expr);
	errors += check_expr(node->else_expr);
	if (errors == 0 && !type_type_equal(node->then_expr->s_type, node->else_expr->s_type))
	{
		errors++;
		typeA = string_type_decl(node->then_expr->s_type);
		typeB = string_type_decl(node->else_expr->s_type);

		pretty_error(node->line, "ternary results are not of the same type (are of types %s and %s)", typeA, typeB);

		free(typeA);
		free(typeB);
	}

	if (errors == 0)
		node->s_type = duplicate_type_decl(node->then_expr->s_type);

	return errors;
}
Exemplo n.º 3
0
int check_binary_op(is_binary_op* node)
{
	int errors = 0;
	char *typeA, *typeB;
	is_type_native type;

	switch (node->type)
	{
		case t_binary_op_assign:
			errors += check_assign_op(node->data.assign);
			if (errors == 0)
				node->s_type = duplicate_type_decl(node->data.assign->s_type);
		break;

		default:
			errors += check_expr(node->data.operands.left);
			errors += check_expr(node->data.operands.right);

			if (errors == 0)
			{
				if (node->data.operands.left->s_type->type == t_type_decl_array_decl ||
					node->data.operands.right->s_type->type == t_type_decl_array_decl)
				{
					errors++;
					pretty_error(node->line, "binary operations are invalid between array types");
				} else
				{
					type = operators_binary[node->type][node->data.operands.left->s_type->data.type_object->type][node->data.operands.right->s_type->data.type_object->type];
					if (type == ERROR)
					{
						errors++;
						pretty_error(node->line, "invalid binary operation between %s and %s",
							typeA = string_type_decl(node->data.operands.left->s_type),
							typeB = string_type_decl(node->data.operands.right->s_type)
						);
						free(typeA);
						free(typeB);
					}
				}
			}

			/* only valid for objects not arrays*/
			if (errors == 0)
				node->s_type = insert_type_decl_object(insert_type_object(type));
		break;
	}

	return errors;
}
Exemplo n.º 4
0
    sc_uint32 unref()
    {
        check_expr(mRefCount > 0);
        --mRefCount;

        return mRefCount;
    }
Exemplo n.º 5
0
int check_while(is_while* node, is_label* label)
{
	int errors = 0;
	char *string;

	int mylabel = ++label_counter; /* setting label for use with loops and break/continue */
	
	if (label)
		node->scope = scope_new(symbol_new_loop(label->name, node->line, mylabel), false);
	else
		node->scope = scope_new(symbol_new_loop(NULL, node->line, mylabel), false);
		
	scope_push(node->scope);
		errors += check_expr(node->cond);
		if (errors == 0)
		{
			if (!type_native_assign_able(t_type_native_bool, node->cond->s_type))
			{
				errors++;
				pretty_error(node->line, "invalid while condition: expected boolean, got %s", string = string_type_decl(node->cond->s_type));
				free(string);
			}
		}

		errors += check_stmt(node->body);
		node->terminates = node->body->terminates;
	scope_pop();
	
	return errors;
}
Exemplo n.º 6
0
int check_do_while(is_do_while* node, is_label* label)
{
	int errors = 0;

	int mylabel = ++label_counter; /* setting label for use with loops and break/continue */

	if (label)
		node->scope = scope_new(symbol_new_loop(label->name, node->line, mylabel), false);
	else
		node->scope = scope_new(symbol_new_loop(NULL, node->line, mylabel), false);
		
	scope_push(node->scope);
		errors += check_stmt(node->body);
		if (errors == 0)
			node->terminates = node->body->terminates;

		errors += check_expr(node->cond);
		if (errors == 0)
		{
			if (!type_native_assign_able(t_type_native_bool, node->cond->s_type))
			{
				errors++;
				pretty_error(node->line, "invalid do..while condition (must be boolean)");
			}
		}
	scope_pop();
	return errors;
}
Exemplo n.º 7
0
static void match_binop(struct expression *expr)
{
	if (expr->op == '^')
		return;
	if (expr->op == '&')
		return;
	if (expr->op == '|')
		return;
	if (expr->op == SPECIAL_RIGHTSHIFT)
		return;
	if (expr->op == SPECIAL_LEFTSHIFT)
		return;

	check_expr(expr->left);
	check_expr(expr->right);
}
Exemplo n.º 8
0
bool ScStruct::append(ScAddr const & elAddr)
{
	check_expr(mContext);
	if (!hasElement(elAddr))
		return mContext->createEdge(sc_type_arc_pos_const_perm, mAddr, elAddr).isValid();

	return false;
}
Exemplo n.º 9
0
ScAddr ScMemoryContext::getEdgeTarget(ScAddr const & edgeAddr) const
{
	check_expr(isValid());
	ScAddr addr;
	if (sc_memory_get_arc_end(mContext, edgeAddr.mRealAddr, &addr.mRealAddr) != SC_RESULT_OK)
		addr.reset();

	return addr;
}
Exemplo n.º 10
0
// std::string persistent test.
void StlAdvancedFeaturesExample::storing_std_strings()
{	
	string kstring = "hello world", *sstring = new string("hi there");
	if (explicit_txn)
		begin_txn(0, penv);

	db_map<string, string> pmap(dmstringdb, NULL);

	pmap[kstring] = *sstring + "!";
	*sstring = pmap[kstring];
	map<string, string> spmap;
	spmap.insert(make_pair(kstring, *sstring));
	cout<<"sstring append ! is : "<<pmap[kstring]
	    <<" ; *sstring is : "<<*sstring;
	delete sstring;
	for (db_map<string, string>::iterator ii = pmap.begin();
	    ii != pmap.end();
	    ++ii) {
		cout << (*ii).first << ": " << (*ii).second << endl;
	} 
	close_db(dmstringdb);
	
	dmstringdb = dbstl::open_db(penv, "db_map_stringdb.db", 
	    dbtype, DB_CREATE | dboflags, 0);
	db_map<string, string> pmap2(dmstringdb, NULL);
	for (db_map<string, string>::iterator ii = pmap2.begin();
	    ii != pmap2.end(); ++ii) {
		cout << (*ii).first << ": " << (*ii).second << endl;
		// assert key/data pair set equal
		check_expr((spmap.count(ii->first) == 1) && 
		    (spmap[ii->first] == ii->second));
	} 
	if (explicit_txn)
		commit_txn(penv);

	db_vector<string> strvctor(10);
	vector<string> sstrvctor(10);
	for (int i = 0; i < 10; i++) {
		strvctor[i] = "abc";
		sstrvctor[i] = strvctor[i];
	}
	check_expr(is_equal(strvctor, sstrvctor));
}
Exemplo n.º 11
0
	void refReplacement(ScTemplateItemValue const & v, ScAddr const & addr)
	{
		if (!v.mReplacementName.empty())
		{
			auto it = mTemplate.mReplacements.find(v.mReplacementName);
			check_expr(it != mTemplate.mReplacements.end());		

			mResultAddrs[it->second] = addr;
			mReplRefs[it->second]++;
		}
	}
Exemplo n.º 12
0
	void unrefReplacement(ScTemplateItemValue const & v)
	{
		if (!v.mReplacementName.empty())
		{
			auto it = mTemplate.mReplacements.find(v.mReplacementName);
			check_expr(it != mTemplate.mReplacements.end());
			
			mReplRefs[it->second]--;
			if (mReplRefs[it->second] == 0)
				mResultAddrs[it->second].reset();
		}
	}
Exemplo n.º 13
0
bool ScMemoryContext::getEdgeInfo(ScAddr const & edgeAddr, ScAddr & outSourceAddr, ScAddr & outTargetAddr) const
{
	check_expr(isValid());
	if (sc_memory_get_arc_info(mContext, *edgeAddr, &outSourceAddr.mRealAddr, &outTargetAddr.mRealAddr) != SC_RESULT_OK)
	{
		outSourceAddr.reset();
		outTargetAddr.reset();

		return false;
	}
		
	return true;
}
Exemplo n.º 14
0
bool ScMemoryContext::helperResolveSystemIdtf(std::string const & sysIdtf, ScAddr & outAddr, bool bForceCreation /*= false*/)
{
	check_expr(isValid());
    outAddr.reset();
    bool result = helperFindBySystemIdtf(sysIdtf, outAddr);
    if (!result && bForceCreation)
    {
        outAddr = createNode(sc_type_const);
        if (outAddr.isValid())
            result = helperSetSystemIdtf(sysIdtf, outAddr);
    }
    return result;
}
Exemplo n.º 15
0
bool ScStruct::remove(ScAddr const & elAddr)
{
	check_expr(mContext);
	bool found = false;
	ScIterator3Ptr iter = mContext->iterator3(mAddr, SC_TYPE(sc_type_arc_pos_const_perm), elAddr);
	while (iter->next())
	{
		mContext->eraseElement(iter->value(1));
		found = true;
	}

	return found;
}
Exemplo n.º 16
0
bool check_assignment(struct assignment *assignment, struct symtable *syms)
{
  if(assignment->e1->exprtype == identtype)
  {
    if(find_var(syms->variables,assignment->e1->val.ident) != NULL && 
        find_var(syms->variables,assignment->e1->val.ident)->constante)
    {
      error(assignment->pos, "assignment of read-only variable %s", assignment->e1->val.ident);
      return false;
    }
  }
  char *t1 = check_expr(assignment->e1, syms);
  char *t2 = check_expr(assignment->e2, syms);
  if (!t1 || !t2)
    return false;
  if (!equal_types(t1, t2, syms))
  {
    error(assignment->pos, "incompatible types: %s and %s.", t1, t2);
    return false;
  }
  return true;
}
Exemplo n.º 17
0
	void iteration(size_t orderIndex, ScTemplateSearchResult & result)
    {
		size_t const constrIndex = mTemplate.mSearchCachedOrder[orderIndex];

        check_expr(constrIndex < mTemplate.mConstructions.size());
		size_t const finishIdx = mTemplate.mConstructions.size() - 1;
        size_t resultIdx = constrIndex * 3;
		
		/// TODO: prevent recursive search and make test for that case

		ScTemplateConstr3 const & constr = mTemplate.mConstructions[constrIndex];
		ScTemplateItemValue const * values = constr.getValues();
        ScIterator3Ptr const it3 = createIterator(constr);
        while (it3->next())
        {
			/// check if search in structure
			if (mScStruct.isValid())
			{
				if (!checkInStruct(it3->value(0)) ||
					!checkInStruct(it3->value(1)) ||
					!checkInStruct(it3->value(2)))
				{
					continue;
				}
			}

            // do not make cycle for optimization issues (remove comparsion expresion)
            mResultAddrs[resultIdx] = it3->value(0);
            mResultAddrs[resultIdx + 1] = it3->value(1);
            mResultAddrs[resultIdx + 2] = it3->value(2);

			refReplacement(values[0], it3->value(0));
			refReplacement(values[1], it3->value(1));
			refReplacement(values[2], it3->value(2));			

			if (orderIndex == finishIdx)
            {
                result.mResults.push_back(mResultAddrs);
            }
            else
            {
				iteration(orderIndex + 1, result);
            }

			unrefReplacement(values[0]);
			unrefReplacement(values[1]);
			unrefReplacement(values[2]);
        }
    }
Exemplo n.º 18
0
bool ScMemoryContext::getLinkContent(ScAddr const & addr, ScStream & stream)
{
    check_expr(isValid());

    sc_stream * s = 0;
    if (sc_memory_get_link_content(mContext, addr.mRealAddr, &s) != SC_RESULT_OK)
    {
        stream.reset();
        return false;
    }

    stream.init(s);

    return stream.isValid();
}
Exemplo n.º 19
0
int check_dims_sized(is_dims_sized* node)
{
	int errors = 0;

	errors += check_expr(node);
	if (errors == 0)
	{
		if (!type_native_assign_able(t_type_native_int, node->s_type))
		{
			errors++;
			pretty_error(node->line, "invalid array size (must be convertible to int)");
		}
	}

	return errors;
}
Exemplo n.º 20
0
void check_stmt(tree t) {
	for( ; t != NULL; t = t->next ) {
		switch (t->kind) {
			case If:
			case Elseif:
				if( check_expr(t->first) != Boolean ) {
					print_error("Invalid IF statement.", t);
				}
				check_stmt(t->second);
				check_stmt(t->third);
				continue;
			case Else:
				check_stmt(t->first);
				continue;
			case Exit:
				if(check_expr(t->first) != Boolean) {
					print_error("exit when must produce a boolean.", t);
				}
				continue;
			case Assign:
				if(t->first->kind == Obracket | check_expr(t->first) != check_expr(t->second)) {
					print_error("Invalid assignment statement.", t);
				}
				continue;
			case For:
				new_scope();
				declare_var(id_name(t->first->value), Integer);
				if(check_expr(t->second->first) != Integer | check_expr(t->second->second) != Integer)//TODO or add a range check
					print_error("Invalid range.", t->second);
				
				check_stmt(t->third);
				end_scope();
				continue;
			case Declaration:;
				if(t->second->kind == Array) {
					for(tree cur = t->first; cur != NULL; cur = cur->next)
						declare_array(id_name(cur->value), t->second->second->kind);
				} else {
					for(tree cur = t->first; cur != NULL; cur = cur->next)
						declare_var(id_name(cur->value), t->second->kind);
				}
				continue;
			case Declare:
				new_scope();
				check_stmt(t->first);
				check_stmt(t->second);
				end_scope();
				continue;
			default:
				print_error("Token of this type not checked by check_stmt.", t);
				continue;
		}
	}
}
Exemplo n.º 21
0
int check_expr_list(is_expr_list* node)
{
	int errors = 0;

	if (node)
	{
		errors += check_expr(node->node);
		errors += check_expr_list(node->next);

		if (node->next)
			node->length = node->next->length+1;
		else
			node->length = 1;
	}

	return errors;
}
Exemplo n.º 22
0
bool parseTimeStamp(std::string str, std::tm & outValue)
{
    //2016-02-16T00:30:13.529Z
    tStringVector tokens;
    tokenize(str, tokens, "-T:.");

    check_expr(tokens.size() == 7);
    outValue.tm_year = atoi(tokens[0].c_str());
    outValue.tm_mon = atoi(tokens[1].c_str());
    outValue.tm_mday = atoi(tokens[2].c_str());

    outValue.tm_hour = atoi(tokens[3].c_str());
    outValue.tm_min = atoi(tokens[4].c_str());
    outValue.tm_sec = atoi(tokens[5].c_str());

    return true;
}
Exemplo n.º 23
0
int check_var_initializer(is_var_initializer* node)
{
	int errors = 0;

	switch(node->type)
	{
		case t_var_initializer_val_arr:
			errors += check_var_initializer_list(node->data.array);

		break;

		case t_var_initializer_expr:
			errors += check_expr(node->data.expr);
		break;
	}

	return errors;
}
Exemplo n.º 24
0
int check_return(is_return* node)
{
	int errors = 0;
	SCOPE* scope;

	is_type_decl *type = NULL, *typeR;
	char *typeA, *typeB;

	if (node->value)
	{
		errors += check_expr(node->value);
		typeR = node->value->s_type;
	} else
	{
		type = new_type_decl_void(node->line);
		typeR = type;
	}

	if (errors == 0)
	{
		scope = scope_get_by_name(symtab, NULL, t_symbol_func);
		node->symbol = scope->symbol;
		if (!type_type_equal(typeR, node->symbol->data.func_data.type))
		{
			typeA = string_type_decl(typeR);

			typeB = string_type_decl(node->symbol->data.func_data.type);

			errors++;
			pretty_error(node->line, "invalid return type %s should be of type %s",
				typeA,
				typeB
			);

			free(typeA);
			free(typeB);
		}
	}

	if (type)
		free_type_decl(type);

	return errors;
}
Exemplo n.º 25
0
bool ScMemoryContext::findLinksByContent(ScStream const & stream, tAddrList & found)
{
    check_expr(isValid());

    sc_addr * result = 0;
    sc_uint32 resultCount = 0;

    found.clear();
    if (sc_memory_find_links_with_content(mContext, stream.mStream, &result, &resultCount) != SC_RESULT_OK)
        return false;

    for (sc_uint32 i = 0; i < resultCount; ++i)
		found.push_back(ScAddr(result[i]));

	if (result)
		sc_memory_free_buff(result);

    return found.size() > 0;
}
Exemplo n.º 26
0
bool ScStruct::append(ScAddr const & elAddr, ScAddr const & attrAddr)
{
	check_expr(mContext);
	if (!hasElement(elAddr))
	{
		ScAddr const edge = mContext->createEdge(sc_type_arc_pos_const_perm, mAddr, elAddr);
		if (edge.isValid())
		{
			ScAddr const edge2 = mContext->createEdge(sc_type_arc_pos_const_perm, attrAddr, edge);
			if (edge2.isValid())
				return true;

			// cleanup
			mContext->eraseElement(edge);
		}
	}

	return false;
}
Exemplo n.º 27
0
int check_unary_op(is_unary_op* node)
{
	is_type_native type;
	char* typeA;
	int errors = 0;

	switch (node->type)
	{
		case t_unary_op_operation:
			errors += check_expr(node->data.operation.expr);
			if (errors == 0)
			{
				if (node->data.operation.expr->s_type->type != t_type_decl_array_decl)
				{
					type = operators_unary[node->data.operation.op][node->data.operation.expr->s_type->type];
					if (type == ERROR)
					{
						errors++;
						pretty_error(node->line, "unary operation with %s type is invalid",
							typeA = string_type_decl(node->data.operation.expr->s_type));
						free(typeA);
					} else
						node->s_type = duplicate_type_decl(node->data.operation.expr->s_type);
				} else
				{
					errors++;
					pretty_error(node->line, "unary operations are invalid between array types");
				}
			}
		break;

		case t_unary_op_incr_op:
			errors += check_incr_op(node->data.incr);
			if (errors == 0)
			{
				node->s_type = duplicate_type_decl(node->data.incr->s_type);
				node->data.incr->used = true;
			}
		break;	
	}

	return errors;
}
Exemplo n.º 28
0
int check_switch(is_switch* node)
{
	int errors = 0;
	int mylabel = ++label_counter; /* setting label for use with break */
	char *type;

	if (node->label)
		errors += check_label(node->label);

	errors += check_expr(node->expr);

	if (errors == 0)
	{
		if (node->expr->s_type->type == t_type_decl_array_decl)
		{
			errors++;

			type = string_type_decl(node->expr->s_type);
			pretty_error(node->line, "switch statement expression must be of object type (got %s)", type);
			free(type);
		}
	}

	if (errors == 0)
	{
		if (node->label)
			node->scope = scope_new(symbol_new_switch(node->label->name, node->line, mylabel, node->expr->s_type->data.type_object, symtab->framepos++), false);
		else
			node->scope = scope_new(symbol_new_switch(NULL, node->line, mylabel, node->expr->s_type->data.type_object, symtab->framepos++), false);

		scope_push(node->scope);
			check_switch_stmt_list(node->list, node);

			if (errors == 0)
				node->terminates = (node->list ? node->list->terminates : true);
		scope_pop();
 	}

	return errors;
}
Exemplo n.º 29
0
std::string ScMemoryContext::helperGetSystemIdtf(ScAddr const & addr)
{
	check_expr(isValid());
	ScAddr idtfLink;
	if (sc_helper_get_system_identifier_link(mContext, *addr, &idtfLink.mRealAddr) == SC_RESULT_OK)
	{
		if (idtfLink.isValid())
		{
			ScStream stream;
			if (getLinkContent(idtfLink, stream))
			{
				std::string result;
				if (StreamConverter::streamToString(stream, result))
				{
					return result;
				}
			}
		}
	}

	return std::string("");
}
Exemplo n.º 30
0
int check_if(is_if* node)
{
	int errors = 0;
	char* typeA;

	errors += check_expr(node->cond);
	if (errors == 0 && !type_native_assign_able(t_type_native_bool, node->cond->s_type))
	{
		errors++;
		pretty_error(node->line, "if conditional is not boolean (is of type %s)", typeA = string_type_decl(node->cond->s_type));
		free(typeA);
	}	

	errors += check_stmt(node->then_body);
	node->terminates = node->then_body->terminates && node->else_body != NULL;
	if (node->else_body)
	{
		errors += check_stmt(node->else_body);
		node->terminates &= node->else_body->terminates;
	}

	return errors;
}