Ejemplo n.º 1
0
int
processBreakPoint( int streamId, RuleEngineEventParam *param,
                   Node *node, int curStat ) {

    char myhdr[HEADER_TYPE_LEN];
    snprintf( myhdr, HEADER_TYPE_LEN - 1,   "idbug:%s", param->actionName );

    if ( breakPointsInx > 0 && node != NULL ) {
        for ( int i = 0; i < breakPointsInx; i++ ) {
            if ( breakPoints[i].base != NULL && breakPoints[i].actionName != NULL &&
                    node->expr >= breakPoints[i].start && node->expr < breakPoints[i].finish &&
                    strcmp( node->base, breakPoints[i].base ) == 0 &&
                    strncmp( param->actionName, breakPoints[i].actionName, strlen( breakPoints[i].actionName ) ) == 0 ) {
                char buf[MAX_NAME_LEN];
                snprintf( buf, MAX_NAME_LEN, "Breaking at BreakPoint %i:%s\n", i , breakPoints[i].actionName );
                char mymsg[MAX_NAME_LEN];
                generateErrMsg( buf, node->expr, node->base, mymsg );
                _writeXMsg( streamId, myhdr, mymsg );
                snprintf( mymsg, MAX_NAME_LEN, "%s\n", param->actionName );
                _writeXMsg( streamId, myhdr, mymsg );
                return REDEBUG_WAIT;
            }
        }
    }
    return curStat;
}
Ejemplo n.º 2
0
ExprType *typeRule( RuleDesc *rule, Env *funcDesc, Hashtable *varTypes, List *typingConstraints, rError_t *errmsg, Node **errnode, Region *r ) {
    /* printf("%s\n", node->subtrees[0]->text); */
    addRErrorMsg( errmsg, -1, ERR_MSG_SEP );
    char buf[ERR_MSG_LEN];
    Node *node = rule->node;
    int dynamictyping = rule->dynamictyping;

    ExprType *resType = typeExpression3( node->subtrees[1], dynamictyping, funcDesc, varTypes, typingConstraints, errmsg, errnode, r );
    /*printf("Type %d\n",resType->t); */
    RE_ERROR( getNodeType( resType ) == T_ERROR );
    if ( getNodeType( resType ) != T_BOOL && getNodeType( resType ) != T_VAR && getNodeType( resType ) != T_DYNAMIC ) {
        char buf2[1024], buf3[ERR_MSG_LEN];
        typeToString( resType, varTypes, buf2, 1024 );
        snprintf( buf3, ERR_MSG_LEN, "error: the type %s of the rule condition is not supported", buf2 );
        generateErrMsg( buf3, NODE_EXPR_POS( node->subtrees[1] ), node->subtrees[1]->base, buf );
        addRErrorMsg( errmsg, RE_TYPE_ERROR, buf );
        RE_ERROR( 1 );
    }
    resType = typeExpression3( node->subtrees[2], dynamictyping, funcDesc, varTypes, typingConstraints, errmsg, errnode, r );
    RE_ERROR( getNodeType( resType ) == T_ERROR );
    resType = typeExpression3( node->subtrees[3], dynamictyping, funcDesc, varTypes, typingConstraints, errmsg, errnode, r );
    RE_ERROR( getNodeType( resType ) == T_ERROR );
    /* printVarTypeEnvToStdOut(varTypes); */
    RE_ERROR( solveConstraints( typingConstraints, varTypes, errmsg, errnode, r ) == ABSURDITY );
    int i;
    for ( i = 1; i <= 3; i++ ) { // 1 = cond, 2 = actions, 3 = recovery
        postProcessCoercion( node->subtrees[i], varTypes, errmsg, errnode, r );
        postProcessActions( node->subtrees[i], funcDesc, errmsg, errnode, r );
    }
    /*printTree(node, 0); */
    return newSimpType( T_INT, r );

error:
    snprintf( buf, ERR_MSG_LEN, "type error: in rule %s", node->subtrees[0]->text );
    addRErrorMsg( errmsg, RE_TYPE_ERROR, buf );
    return resType;

}
Ejemplo n.º 3
0
/* parse and compute an expression
 *
 */
Res *parseAndComputeExpression( char *expr, Env *env, ruleExecInfo_t *rei, int reiSaveFlag, rError_t *errmsg, Region *r ) {
    Res *res = NULL;
    char buf[ERR_MSG_LEN > 1024 ? ERR_MSG_LEN : 1024];
    int rulegen;
    Node *node = NULL, *recoNode = NULL;

#ifdef DEBUG
    snprintf( buf, 1024, "parseAndComputeExpression: %s\n", expr );
    writeToTmp( "entry.log", buf );
#endif
    if ( overflow( expr, MAX_RULE_LEN ) ) {
        addRErrorMsg( errmsg, RE_BUFFER_OVERFLOW, "error: potential buffer overflow" );
        return newErrorRes( r, RE_BUFFER_OVERFLOW );
    }
    Pointer *e = newPointer2( expr );
    ParserContext *pc = newParserContext( errmsg, r );
    if ( e == NULL ) {
        addRErrorMsg( errmsg, RE_POINTER_ERROR, "error: can not create pointer." );
        res = newErrorRes( r, RE_POINTER_ERROR );
        RETURN;
    }
    rulegen = isRuleGenSyntax( expr );

    if ( rulegen ) {
        node = parseTermRuleGen( e, rulegen, pc );
    }
    else {
        node = parseActionsRuleGen( e, rulegen, 1, pc );
    }
    if ( node == NULL ) {
        addRErrorMsg( errmsg, RE_OUT_OF_MEMORY, "error: out of memory." );
        res = newErrorRes( r, RE_OUT_OF_MEMORY );
        RETURN;
    }
    else if ( getNodeType( node ) == N_ERROR ) {
        generateErrMsg( "error: syntax error", NODE_EXPR_POS( node ), node->base, buf );
        addRErrorMsg( errmsg, RE_PARSER_ERROR, buf );
        res = newErrorRes( r, RE_PARSER_ERROR );
        RETURN;
    }
    else {
        Token *token;
        token = nextTokenRuleGen( e, pc, 0, 0 );
        if ( strcmp( token->text, "|" ) == 0 ) {
            recoNode = parseActionsRuleGen( e, rulegen, 1, pc );
            if ( recoNode == NULL ) {
                addRErrorMsg( errmsg, RE_OUT_OF_MEMORY, "error: out of memory." );
                res = newErrorRes( r, RE_OUT_OF_MEMORY );
                RETURN;
            }
            else if ( getNodeType( recoNode ) == N_ERROR ) {
                generateErrMsg( "error: syntax error", NODE_EXPR_POS( recoNode ), recoNode->base, buf );
                addRErrorMsg( errmsg, RE_PARSER_ERROR, buf );
                res = newErrorRes( r, RE_PARSER_ERROR );
                RETURN;
            }
            token = nextTokenRuleGen( e, pc, 0, 0 );
        }
        if ( token->type != TK_EOS ) {
            Label pos;
            getFPos( &pos, e, pc );
            generateErrMsg( "error: unparsed suffix", pos.exprloc, pos.base, buf );
            addRErrorMsg( errmsg, RE_UNPARSED_SUFFIX, buf );
            res = newErrorRes( r, RE_UNPARSED_SUFFIX );
            RETURN;
        }
    }
    res = computeNode( node, NULL, env, rei, reiSaveFlag, errmsg, r );
ret:
    deleteParserContext( pc );
    deletePointer( e );
    return res;
}
Ejemplo n.º 4
0
ExprType *typeRuleSet( RuleSet *ruleset, rError_t *errmsg, Node **errnode, Region *r ) {
    Env *funcDesc = ruleEngineConfig.extFuncDescIndex;
    Hashtable *ruleType = newHashTable2( MAX_NUM_RULES * 2, r );
    ExprType *res;
    int i;
    for ( i = 0; i < ruleset->len; i++ ) {
        RuleDesc *rule = ruleset->rules[i];
        if ( rule->ruleType == RK_REL || rule->ruleType == RK_FUNC ) {
            List *typingConstraints = newList( r );
            Hashtable *varTypes = newHashTable2( 100, r );
            ExprType *restype = typeRule( rule, funcDesc, varTypes, typingConstraints, errmsg, errnode, r );
            /*char buf[1024]; */
            /*typingConstraintsToString(typingConstraints, buf, 1024); */
            /*printf("rule %s, typing constraints: %s\n", ruleset->rules[i]->subtrees[0]->text, buf); */
            if ( getNodeType( restype ) == T_ERROR ) {
                res = restype;
                char *errbuf = ( char * ) malloc( ERR_MSG_LEN * 1024 * sizeof( char ) );
                errMsgToString( errmsg, errbuf, ERR_MSG_LEN * 1024 );
#ifdef DEBUG
                writeToTmp( "ruleerr.log", errbuf );
                writeToTmp( "ruleerr.log", "\n" );
#endif
                rodsLog( LOG_ERROR, "%s", errbuf );
                free( errbuf );
                freeRErrorContent( errmsg );
                RETURN;
            }
            /* check that function names are unique and do not conflict with system msis */
            char errbuf[ERR_MSG_LEN];
            char *ruleName = rule->node->subtrees[0]->text;
            FunctionDesc *fd;
            if ( ( fd = ( FunctionDesc * )lookupFromEnv( funcDesc, ruleName ) ) != NULL ) {
                if ( getNodeType( fd ) != N_FD_EXTERNAL && getNodeType( fd ) != N_FD_RULE_INDEX_LIST ) {
                    char *err;
                    switch ( getNodeType( fd ) ) {
                    case N_FD_CONSTRUCTOR:
                        err = "redefinition of constructor";
                        break;
                    case N_FD_DECONSTRUCTOR:
                        err = "redefinition of deconstructor";
                        break;
                    case N_FD_FUNCTION:
                        err = "redefinition of system microservice";
                        break;
                    default:
                        err = "redefinition of system symbol";
                        break;
                    }

                    generateErrMsg( err, NODE_EXPR_POS( rule->node ), rule->node->base, errbuf );
                    addRErrorMsg( errmsg, RE_FUNCTION_REDEFINITION, errbuf );
                    res = newErrorType( RE_FUNCTION_REDEFINITION, r );
                    *errnode = rule->node;
                    RETURN;
                }
            }

            RuleDesc *rd = ( RuleDesc * )lookupFromHashTable( ruleType, ruleName );
            if ( rd != NULL ) {
                if ( rule->ruleType == RK_FUNC || rd ->ruleType == RK_FUNC ) {
                    generateErrMsg( "redefinition of function", NODE_EXPR_POS( rule->node ), rule->node->base, errbuf );
                    addRErrorMsg( errmsg, RE_FUNCTION_REDEFINITION, errbuf );
                    generateErrMsg( "previous definition", NODE_EXPR_POS( rd->node ), rd->node->base, errbuf );
                    addRErrorMsg( errmsg, RE_FUNCTION_REDEFINITION, errbuf );
                    res = newErrorType( RE_FUNCTION_REDEFINITION, r );
                    *errnode = rule->node;
                    RETURN;
                }
            }
            else {
                insertIntoHashTable( ruleType, ruleName, rule );
            }
        }
    }
    res = newSimpType( T_INT, r ); /* Although a rule set does not have type T_INT, return T_INT to indicate success. */

ret:
    return res;
}