y_filter.cpp
来自「Pegasus is an open-source implementation」· C++ 代码 · 共 1,323 行 · 第 1/3 页
CPP
1,323 行
#if YYLSP_NEEDED /* Similarly for the default location. Let the user run additional commands if for instance locations are ranges. */ yyloc = yylsp[1-yylen]; YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);#endif#if YYDEBUG /* We have to keep this `#if YYDEBUG', since we use variables which are defined only if `YYDEBUG' is set. */ if (yydebug) { int yyi; YYFPRINTF (stderr, "Reducing via rule %d (line %d), ", yyn, yyrline[yyn]); /* Print the symbols being reduced, and their result. */ for (yyi = yyprhs[yyn]; yyrhs[yyi] > 0; yyi++) YYFPRINTF (stderr, "%s ", yytname[yyrhs[yyi]]); YYFPRINTF (stderr, " -> %s\n", yytname[yyr1[yyn]]); }#endif switch (yyn) {case 3:#line 84 "filter.y"{ if(NULL != (yyval.filter_filter = lslpAllocFilter(yyvsp[-2].filter_int))) { yyval.filter_filter->nestingLevel = nesting_level; if(! _LSLP_IS_EMPTY(&reducedFilters) ) { lslpLDAPFilter *temp = (lslpLDAPFilter *)reducedFilters.next; while(! _LSLP_IS_HEAD(temp)) { if(temp->nestingLevel == nesting_level + 1) { lslpLDAPFilter *nest = temp; temp = temp->next; _LSLP_UNLINK(nest); _LSLP_INSERT_BEFORE(nest, (lslpLDAPFilter *)&(yyval.filter_filter->children)) ; } else {temp = temp->next; } } _LSLP_INSERT_BEFORE( (filterHead *)yyval.filter_filter, &reducedFilters); } else { lslpFreeFilter(yyval.filter_filter) ; yyval.filter_filter = NULL ; } } ; break;}case 4:#line 102 "filter.y"{ yyval.filter_filter = yyvsp[-1].filter_filter; if(yyvsp[-1].filter_filter != NULL) { yyvsp[-1].filter_filter->nestingLevel = nesting_level; _LSLP_INSERT_BEFORE((filterHead *)yyvsp[-1].filter_filter, &reducedFilters) ; } ; break;}case 5:#line 111 "filter.y"{ nesting_level++; ; break;}case 6:#line 114 "filter.y"{ nesting_level--; ; break;}case 9:#line 120 "filter.y"{ yyval.filter_int = filterlval.filter_int; ; break;}case 10:#line 124 "filter.y"{ /* presence test binds to single operand */ if(NULL != (yyval.filter_filter = lslpAllocFilter(expr_present))) { lslpAttrList *attr = lslpAllocAttr(yyvsp[-1].filter_string, string, "*", (int16)strlen("*") + 1); if(attr != NULL) { _LSLP_INSERT(attr, &(yyval.filter_filter->attrs)); } else { lslpFreeFilter(yyval.filter_filter); yyval.filter_filter = NULL; } } ; break;}case 11:#line 133 "filter.y"{ /* must be an int or a bool */ /* remember to touch up the token values to match the enum in lslp.h */ if(NULL != (yyval.filter_filter = lslpAllocFilter(yyvsp[-1].filter_int))) { lslpAttrList *attr = lslpAllocAttr(yyvsp[-2].filter_string, integer, &(yyvsp[0].filter_int), sizeof(yyvsp[0].filter_int)); if(attr != NULL) { _LSLP_INSERT(attr, &(yyval.filter_filter->attrs)); } else { lslpFreeFilter(yyval.filter_filter); yyval.filter_filter = NULL ; } } ; break;}case 12:#line 143 "filter.y"{ /* must be an int or a bool */ /* remember to touch up the token values to match the enum in lslp.h */ if(NULL != (yyval.filter_filter = lslpAllocFilter(yyvsp[-1].filter_int))) { lslpAttrList *attr = lslpAllocAttr(yyvsp[-2].filter_string, bool_type, &(yyvsp[0].filter_int), sizeof(yyvsp[0].filter_int)); if(attr != NULL) { _LSLP_INSERT(attr, &(yyval.filter_filter->attrs)); } else { lslpFreeFilter(yyval.filter_filter); yyval.filter_filter = NULL ; } } ; break;}case 13:#line 153 "filter.y"{ /* both operands are strings */ if(NULL != (yyval.filter_filter = lslpAllocFilter(yyvsp[-1].filter_int))) { lslpAttrList *attr = lslpAllocAttr(yyvsp[-2].filter_string, string, yyvsp[0].filter_string, (int16)strlen(yyvsp[0].filter_string) + 1 ); if(attr != NULL) { _LSLP_INSERT(attr, &(yyval.filter_filter->attrs)); } else { lslpFreeFilter(yyval.filter_filter); yyval.filter_filter = NULL ; } } ; break;}case 17:#line 168 "filter.y"{ yyval.filter_int = filterlval.filter_int; ; break;}}#line 705 "bison.simple" yyvsp -= yylen; yyssp -= yylen;#if YYLSP_NEEDED yylsp -= yylen;#endif#if YYDEBUG if (yydebug) { short *yyssp1 = yyss - 1; YYFPRINTF (stderr, "state stack now"); while (yyssp1 != yyssp) YYFPRINTF (stderr, " %d", *++yyssp1); YYFPRINTF (stderr, "\n"); }#endif *++yyvsp = yyval;#if YYLSP_NEEDED *++yylsp = yyloc;#endif /* Now `shift' the result of the reduction. Determine what state that goes to, based on the state we popped back to and the rule number reduced by. */ yyn = yyr1[yyn]; yystate = yypgoto[yyn - YYNTBASE] + *yyssp; if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp) yystate = yytable[yystate]; else yystate = yydefgoto[yyn - YYNTBASE]; goto yynewstate;/*------------------------------------.| yyerrlab -- here on detecting error |`------------------------------------*/yyerrlab: /* If not already recovering from an error, report this error. */ if (!yyerrstatus) { ++yynerrs;#ifdef YYERROR_VERBOSE yyn = yypact[yystate]; if (yyn > YYFLAG && yyn < YYLAST) { YYSIZE_T yysize = 0; char *yymsg; int yyx, yycount; yycount = 0; /* Start YYX at -YYN if negative to avoid negative indexes in YYCHECK. */ for (yyx = yyn < 0 ? -yyn : 0; yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++) if (yycheck[yyx + yyn] == yyx) yysize += yystrlen (yytname[yyx]) + 15, yycount++; yysize += yystrlen ("parse error, unexpected ") + 1; yysize += yystrlen (yytname[YYTRANSLATE (yychar)]); yymsg = (char *) YYSTACK_ALLOC (yysize); if (yymsg != 0) { char *yyp = yystpcpy (yymsg, "parse error, unexpected "); yyp = yystpcpy (yyp, yytname[YYTRANSLATE (yychar)]); if (yycount < 5) { yycount = 0; for (yyx = yyn < 0 ? -yyn : 0; yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++) if (yycheck[yyx + yyn] == yyx) { const char *yyq = ! yycount ? ", expecting " : " or "; yyp = yystpcpy (yyp, yyq); yyp = yystpcpy (yyp, yytname[yyx]); yycount++; } } yyerror (yymsg); YYSTACK_FREE (yymsg); } else yyerror ("parse error; also virtual memory exhausted"); } else#endif /* defined (YYERROR_VERBOSE) */ yyerror ("parse error"); } goto yyerrlab1;/*--------------------------------------------------.| yyerrlab1 -- error raised explicitly by an action |`--------------------------------------------------*/yyerrlab1: if (yyerrstatus == 3) { /* If just tried and failed to reuse lookahead token after an error, discard it. */ /* return failure if at end of input */ if (yychar == YYEOF) YYABORT; YYDPRINTF ((stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1])); yychar = YYEMPTY; } /* Else will try to reuse lookahead token after shifting the error token. */ yyerrstatus = 3; /* Each real token shifted decrements this */ goto yyerrhandle;/*-------------------------------------------------------------------.| yyerrdefault -- current state does not do anything special for the || error token. |`-------------------------------------------------------------------*/yyerrdefault:#if 0 /* This is wrong; only states that explicitly want error tokens should shift them. */ /* If its default is to accept any token, ok. Otherwise pop it. */ yyn = yydefact[yystate]; if (yyn) goto yydefault;#endif/*---------------------------------------------------------------.| yyerrpop -- pop the current state because it cannot handle the || error token |`---------------------------------------------------------------*/yyerrpop: if (yyssp == yyss) YYABORT; yyvsp--; yystate = *--yyssp;#if YYLSP_NEEDED yylsp--;#endif#if YYDEBUG if (yydebug) { short *yyssp1 = yyss - 1; YYFPRINTF (stderr, "Error: state stack now"); while (yyssp1 != yyssp) YYFPRINTF (stderr, " %d", *++yyssp1); YYFPRINTF (stderr, "\n"); }#endif/*--------------.| yyerrhandle. |`--------------*/yyerrhandle: yyn = yypact[yystate]; if (yyn == YYFLAG) goto yyerrdefault; yyn += YYTERROR; if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR) goto yyerrdefault; yyn = yytable[yyn]; if (yyn < 0) { if (yyn == YYFLAG) goto yyerrpop; yyn = -yyn; goto yyreduce; } else if (yyn == 0) goto yyerrpop; if (yyn == YYFINAL) YYACCEPT; YYDPRINTF ((stderr, "Shifting error token, ")); *++yyvsp = yylval;#if YYLSP_NEEDED *++yylsp = yylloc;#endif yystate = yyn; goto yynewstate;/*-------------------------------------.| yyacceptlab -- YYACCEPT comes here. |`-------------------------------------*/yyacceptlab: yyresult = 0; goto yyreturn;/*-----------------------------------.| yyabortlab -- YYABORT comes here. |`-----------------------------------*/yyabortlab: yyresult = 1; goto yyreturn;/*---------------------------------------------.| yyoverflowab -- parser overflow comes here. |`---------------------------------------------*/yyoverflowlab: yyerror ("parser stack overflow"); yyresult = 2; /* Fall through. */yyreturn:#ifndef yyoverflow if (yyss != yyssa) YYSTACK_FREE (yyss);#endif return yyresult;}#line 171 "filter.y"lslpLDAPFilter *lslpAllocFilter(int filterOperator){ lslpLDAPFilter *filter = (lslpLDAPFilter *)calloc(1, sizeof(lslpLDAPFilter)); if(filter != NULL) { filter->next = filter->prev = filter; if(filterOperator == head) { filter->isHead = TRUE; } else { filter->children.next = filter->children.prev = &(filter->children); filter->children.isHead = 1; filter->attrs.next = filter->attrs.prev = &(filter->attrs); filter->attrs.isHead = 1; filter->_operator = filterOperator; } } return(filter);}void lslpFreeFilter(lslpLDAPFilter *filter){ if(filter->children.next != NULL) { while(! (_LSLP_IS_EMPTY((lslpLDAPFilter *)&(filter->children)))) { lslpLDAPFilter *child = (lslpLDAPFilter *)filter->children.next; _LSLP_UNLINK(child); lslpFreeFilter(child); } } if(filter->attrs.next != NULL) { while(! (_LSLP_IS_EMPTY(&(filter->attrs)))) { lslpAttrList *attrs = filter->attrs.next; _LSLP_UNLINK(attrs); lslpFreeAttr(attrs); } }}void lslpFreeFilterList(lslpLDAPFilter *head, BOOL static_flag){ assert((head != NULL) && (_LSLP_IS_HEAD(head))); while(! (_LSLP_IS_EMPTY(head))) { lslpLDAPFilter *temp = head->next; _LSLP_UNLINK(temp); lslpFreeFilter(temp); } if( static_flag == TRUE) lslpFreeFilter(head); return;}void lslpInitFilterList(void ){ reducedFilters.next = reducedFilters.prev = &reducedFilters; reducedFilters.isHead = TRUE; return;}void lslpCleanUpFilterList(void){ lslpFreeFilterList( (lslpLDAPFilter *)&reducedFilters, FALSE);}lslpLDAPFilter *_lslpDecodeLDAPFilter(char *filter){ lslpLDAPFilter *temp = NULL; uint32 lexer = 0; assert(filter != NULL && strlen(filter)); lslpInitFilterList(); nesting_level = 1; if(0 != (lexer = filter_init_lexer(filter))) { if(filterparse()) { lslpCleanUpFilterList(); } filter_close_lexer(lexer); } if (! _LSLP_IS_EMPTY(&reducedFilters)) { if(NULL != (temp = lslpAllocFilter(ldap_and))) { _LSLP_LINK_HEAD(&(temp->children), &reducedFilters); } } lslpCleanUpFilterList(); return(temp);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?