Ejemplo n.º 1
0
/**
Adds the given function to this scope, if there is not already another function with the same name.

The function's parent will be set to this scope.

@param function The function that should be added to this scope.
@exception already_exists_error Is thrown when a function with the same name as `function's name already exists in this scope.
**/
void omni::core::model::scope::addFunction (std::shared_ptr <function_prototype> function)
{
    std::shared_ptr <function_prototype> func = findFunctionByName (function->getName ());
    if (func.get () != nullptr) {
        throw already_exists_error (domain::function, function->getName ());
    }
    setComponent (domain::function, function->getName (), function);
}
DetectRecursion::ErrorCode DetectRecursion::detectRecursion()
{
    FunctionNode* main = findFunctionByName("main(");
    if (main == NULL)
        return kErrorMissingMain;
    if (main->detectRecursion())
        return kErrorRecursion;
    return kErrorNone;
}
Ejemplo n.º 3
0
bool DetectCallDepth::visitAggregate(Visit visit, TIntermAggregate* node)
{
    switch (node->getOp())
    {
        case EOpPrototype:
            // Function declaration.
            // Don't add FunctionNode here because node->getName() is the
            // unmangled function name.
            break;
        case EOpFunction: {
            // Function definition.
            if (visit == PreVisit) {
                currentFunction = findFunctionByName(node->getName());
                if (currentFunction == NULL) {
                    currentFunction = new FunctionNode(node->getName());
                    functions.push_back(currentFunction);
                }
            } else if (visit == PostVisit) {
                currentFunction = NULL;
            }
            break;
        }
        case EOpFunctionCall: {
            // Function call.
            if (visit == PreVisit) {
                FunctionNode* func = findFunctionByName(node->getName());
                if (func == NULL) {
                    func = new FunctionNode(node->getName());
                    functions.push_back(func);
                }
                if (currentFunction)
                    currentFunction->addCallee(func);
            }
            break;
        }
        default:
            break;
    }
    return true;
}
Ejemplo n.º 4
0
DetectCallDepth::ErrorCode DetectCallDepth::detectCallDepth()
{
    if (maxDepth != FunctionNode::kInfiniteCallDepth) {
        // Check all functions because the driver may fail on them
        // TODO: Before detectingRecursion, strip unused functions.
        for (size_t i = 0; i < functions.size(); ++i) {
            ErrorCode error = detectCallDepthForFunction(functions[i]);
            if (error != kErrorNone)
                return error;
        }
    } else {
        FunctionNode* main = findFunctionByName("main(");
        if (main == NULL)
            return kErrorMissingMain;

        return detectCallDepthForFunction(main);
    }

    return kErrorNone;
}