Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages  

pdl_rule.c File Reference

Implementation of the pdl rules. More...

#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lcmaps_log.h"
#include "pdl_rule.h"
#include "pdl_policy.h"
#include "pdl_variable.h"

Include dependency graph for pdl_rule.c:

Include dependency graph

Go to the source code of this file.

Functions

rule_t_add_rule (const record_t *state, const record_t *true_branch, const record_t *false_branch)
const rule_tfind_state (const rule_t *rule, const char *state)
int find_insert_position (const int *list, const int rule_number, unsigned int high)
unsigned int rule_number (const rule_t *rule)
BOOL make_list (int *new_list, const int *list, const int rule_number, const unsigned int depth)
unsigned int count_rules (const rule_t *rule)
void update_list (unsigned int *rules, unsigned int rule)
const rule_tget_rule_number (unsigned int rule_num)
void start_new_rules (void)
void allow_new_rules (BOOL allow)
rule_tadd_rule (record_t *state, record_t *true_branch, record_t *false_branch)
BOOL check_rule_for_recursion (const rule_t *rule)
recursion_t has_recursion (const rule_t *rule, int *list, unsigned int depth, unsigned int *seen_rules)
void reduce_rule (rule_t *rule)
void show_rules (const rule_t *rule)
void free_rules (rule_t *rule)
const rule_tget_top_rule (void)
void set_top_rule (const rule_t *rule)


Detailed Description

Implementation of the pdl rules.

Author:
G.M. Venekamp (venekamp@nikhef.nl)
Version:
Revision:
1.19
Date:
Date:
2003/09/04 13:47:35

Definition in file pdl_rule.c.


Function Documentation

rule_t * _add_rule ( const record_t * state,
const record_t * true_branch,
const record_t * false_branch )
 

Rules come in three different forms:

  1. a -> b
  2. a -> b | c
  3. ~a ->b
They share a common structure. First the left hand side gives the starting state and right hand side the states to transit to. This means that each rule has a starting state and depending on the form one or two transit states:
  • The first form has only the true transit state;
  • The second form had both true and false transit states;
  • The thrird for has only the false transit state. When either the true or false transit state for a rule does not exists, 0 should be supplied.
Parameters:
state   Starting state
true_branch   True transit state
false_branch   False transit state

Returns:
TRUE if the rule has been added successfully, FALSE otherwise.

Definition at line 144 of file pdl_rule.c.

Referenced by add_rule().

rule_t * add_rule ( record_t * state,
record_t * true_branch,
record_t * false_branch )
 

Add a new rule to the list of rules. This function acts as a wrapper function for _add_rule().

Parameters:
state   Starting state
true_branch   True transit state
false_branch   False transit state

Definition at line 86 of file pdl_rule.c.

void allow_new_rules ( BOOL allow )
 

Is it allowed to add new rules?

Parameters:
allows   TRUE if adding new rules is allowed, FALSE otherwise.

Definition at line 71 of file pdl_rule.c.

BOOL check_rule_for_recursion ( const rule_t * rule )
 

Check the rule for occurances of recursion.

Returns:
TRUE if a recursion have been found, FALSE otherwise.

Definition at line 220 of file pdl_rule.c.

unsigned int count_rules ( const rule_t * rule )
 

Count the number of rules that follow 'rule' inclusive.

Parameters:
rule   The rule to start count from.
Returns:
Number of counted rules.

Definition at line 257 of file pdl_rule.c.

Referenced by check_rule_for_recursion().

int find_insert_position ( const int * list,
const int rule_number,
unsigned int high )
 

Based on a sorted list, find the position where to insert an new element without disturbing the ordering in the list. The search is a binary search.

Parameters:
list   List of sorted numbers.
rule_number   Number to be inserted.
high   Element number of last element in the list.

Returns:
Position of insertion.

Definition at line 488 of file pdl_rule.c.

Referenced by make_list(), and update_list().

const rule_t * find_state ( const rule_t * rule,
const char * state )
 

Find a state with name state.

Parameters:
state   Name of the state to be found.
Returns:
Rule which contains the state or 0 when no such rule could be found.

Definition at line 202 of file pdl_rule.c.

void free_rules ( rule_t * rule )
 

Free all resource associated with the rule.

Parameters:
rule   Rule for which the resources must be freed.

Definition at line 637 of file pdl_rule.c.

const rule_t * get_rule_number ( unsigned int rule_num )
 

Give the position of the rule in the policy, return that rule.

Parameters:
rule_num   Position of the rule in the current policy.
Returns:
Rule that is associated with the rule_num, NULL if the rule cannot be found.

Definition at line 278 of file pdl_rule.c.

Referenced by check_rule_for_recursion().

const rule_t * get_top_rule ( void )
 

Get the top rule.

Returns:
Top rule.

Definition at line 658 of file pdl_rule.c.

recursion_t has_recursion ( const rule_t * rule,
int * list,
unsigned int depth,
unsigned int * seen_rules )
 

Check the a rule for recursion. This is done in a recursive manner. From the top rule, all possible paths are considered. Each path becomes a top of its own and from their all possible paths are traveled. Each time the tree is searched at a greater depth, a list is kept to tell which states have been seen for the current path. In this list of states no duplicates should be present. If a seen state state already appears in the list, the path taken is recursive. This information is propagated back up the traveled tree.

At the same time another list is maintained. In this list all visited states are remembered. Duplicates are not added. When all possible paths have been traveled, the list tells all visited rules. When a particular rule is not part of the tree, it is also not listed in the list. This way one can check for disconnected rules.

Parameters:
rule   Rule to check for recursion.
list   List to keep track of each traveled path.
depth   Current depth of the tree.
seen_rules   Rules that have been visited and hence are part of the path.

Returns:
Whether or not recursion has been detected and also if it has been reported.

Definition at line 318 of file pdl_rule.c.

Referenced by check_rule_for_recursion().

BOOL make_list ( int * new_list,
const int * list,
const int rule_number,
const unsigned int depth )
 

Make a new sorted list based on the current list and the element to be inserted. The element will only be added to the list if it is not already present.

Parameters:
new_list   New list after sorted insertion of new element.
list   Old list.
rule_number   Number to be inserted into the list.
depth   Current depth of the tree. It is used to detmine the number of elements of the list.

Returns:
TRUE if element has been added, FALSE otherwise

Definition at line 526 of file pdl_rule.c.

Referenced by has_recursion().

void reduce_rule ( rule_t * rule )
 

Reduce a rule to its elementry form, i.e. all variables in the rule are substituted by their respective values.

Parameters:
rule   Rule to reduce.

Definition at line 558 of file pdl_rule.c.

unsigned int rule_number ( const rule_t * rule )
 

Given a rule, find the corresponding position in the policy.

Parameters:
rule   Rule of which the position must be found.
Returns:
Position of the rule in the current policy.

Definition at line 425 of file pdl_rule.c.

Referenced by has_recursion().

void set_top_rule ( const rule_t * rule )
 

Set the top rule to a new value.

Parameters:
rule   New value of top rule.

Definition at line 670 of file pdl_rule.c.

void show_rules ( const rule_t * rule )
 

Show a rule and its descendants.

Parameters:
rule   Rule to display.

Definition at line 615 of file pdl_rule.c.

void start_new_rules ( void )
 

Start a new list of rules.

Definition at line 58 of file pdl_rule.c.

Referenced by add_policy().

void update_list ( unsigned int * rules,
unsigned int rule )
 

Update the list that hold the visited rules. This is a sorted list for easy insertion and look-up. Duplicate rules are not inserted. The first element of the list tells the total number of elements that follow.

Note:
The list expects rules to be numbered starting from 1. This is because 0 denotes empty cells. The find_insert_position() returns numbers starting from 0. This is corrected for in this function.
Parameters:
rules   List of visited rules.
rule   rule to insert.

Definition at line 453 of file pdl_rule.c.

Referenced by has_recursion().


Generated at Thu Mar 4 17:39:41 2004 for edg-lcmaps by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001