Пример #1
0
bool ExprFuncNode::checkArg(int arg, ExprType type, ExprVarEnvBuilder& envBuilder) {
    ExprType childType = child(arg)->prep(type.isFP(1), envBuilder);
    _promote[arg] = 0;
    if (ExprType::valuesCompatible(type, childType) && type.isLifeCompatible(childType)) {
        if (type.isFP() && type.dim() > childType.dim()) {
            _promote[arg] = type.dim();
        }
        return true;
    }
    child(arg)->addError("Expected " + type.toString() + " for argument, got " + childType.toString());
    return false;
}
Пример #2
0
ExprType ExprLocalFunctionNode::prep(bool wantScalar, ExprVarEnvBuilder& envBuilder) {
    #if 0 // TODO: no local functions for now
    bool error = false;

    // prep prototype and check for errors
    ExprPrototypeNode* prototype = (ExprPrototypeNode*)child(0);
    ExprVarEnv functionEnv;
    functionEnv.resetAndSetParent(&env);
    if (!prototype->prep(false, functionEnv).isValid()) error = true;

    // decide what return type we want
    bool returnWantsScalar = false;
    if (!error && prototype->isReturnTypeSet()) returnWantsScalar = prototype->returnType().isFP(1);

    // prep block and check for errors
    ExprNode* block = child(1);
    ExprType blockType = block->prep(returnWantsScalar, functionEnv);

    if (!error && blockType.isValid()) {
        if (prototype->isReturnTypeSet()) {
            if (blockType != prototype->returnType()) {
                checkCondition(false,
                               "In function result of block '" + blockType.toString() +
                                   "' does not match given return type " + prototype->returnType().toString(),
                               error);
            }

        } else
            prototype->setReturnType(blockType);
        // register the function in the symbol table

        env.addFunction(prototype->name(), this);
    } else {
        checkCondition(false, "Invalid type for blockType is " + blockType.toString(), error);
        error = true;
    }
    return _type = error ? ExprType().Error() : ExprType().None().Varying();
    #else
    bool error=false;
    checkCondition(false,"Local functions are currently not supported.",error);
    return ExprType().Error();
    #endif
}