Beispiel #1
0
void TypeDeduction::Visit(NewRunnerExpression* node)
{
    node->GetTarget()->Accept(this);
    std::vector<Expression *> *arguments = node->GetArgumentList();
    for (std::vector<Expression *>::iterator it = arguments->begin(); it != arguments->end(); ++it)
    {
        Expression *arg = *it;
        arg->Accept(this);
        //TODO: Check the parameter types, and do implicit conversion if needed
    }

    std::vector<Expression *> *usingRanges = node->GetUsingList();
    
    for (std::vector<Expression *>::iterator it = usingRanges->begin(); it != usingRanges->end(); ++it)
    {
        Expression *expr = *it;
        expr->Accept(this);
    }
    
    
    std::vector<Expression *> *watchingRanges = node->GetWatchingList();
    
    for (std::vector<Expression *>::iterator it = watchingRanges->begin(); it != watchingRanges->end(); ++it)
    {
        Expression *expr = *it;
        expr->Accept(this);
    }
 
    std::vector<Expression *> *space = node->GetSpace();
    
    for (std::vector<Expression *>::iterator it = space->begin(); it != space->end(); ++it)
    {
        Expression *expr = *it;
        expr->Accept(this);
    }

    FunctionType *funcType = dynamic_cast<FunctionType *>(node->GetTarget()->GetTag<Type>("Type"));
    if (funcType == NULL)
    {
        
        CompilationContext::GetInstance()->ReportError(node->SourceLocation, false, "Requires a function type.");
    }

    if (!funcType->GetReturnType()->Equals(new VoidType()))
    {
        
        CompilationContext::GetInstance()->ReportError(node->SourceLocation, false, "Runner function cannot have return value.");
    }
    node->SetTag<Type>("Type", funcType->GetReturnType());
}
Beispiel #2
0
void TypeDeduction::Visit(CallExpression* node)
{
    node->GetTarget()->Accept(this);
    std::vector<Expression *> *arguments = node->GetArgumentList();
    for (std::vector<Expression *>::iterator it = arguments->begin(); it != arguments->end(); ++it)
    {
        Expression *arg = *it;
        arg->Accept(this);
        //TODO: Check the parameter types, and do implicit conversion if needed
    }

    FunctionType *funcType = dynamic_cast<FunctionType *>(node->GetTarget()->GetTag<Type>("Type"));
    if (funcType == NULL)
    {
        
        CompilationContext::GetInstance()->ReportError(node->SourceLocation, false, "Requires a function type.");
    }

    node->SetTag<Type>("Type", funcType->GetReturnType());
}
Beispiel #3
0
Type* CallExpression::GetType()
{
    FunctionType *type = dynamic_cast<FunctionType *>(_target->GetType());
    return type->GetReturnType();
}