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

/Users/trevorw/projects/release/covered-0.7.4/src/iter.c File Reference


Detailed Description

Author:
Trevor Williams (phase1geo@gmail.com)
Date:
10/24/2002

#include <stdlib.h>
#include <assert.h>
#include "defines.h"
#include "iter.h"
#include "profiler.h"

Functions

void stmt_iter_reset (stmt_iter *si, stmt_link *start)
 Resets the specified statement iterator at start point.

void stmt_iter_copy (stmt_iter *si, stmt_iter *orig)
 Copies the given statement iterator.

void stmt_iter_next (stmt_iter *si)
 Moves to the next statement link.

void stmt_iter_reverse (stmt_iter *si)
 Reverses iterator flow and advances to next statement link.

void stmt_iter_find_head (stmt_iter *si, bool skip)
 Sets specified iterator to start with statement head for ordering.

void stmt_iter_get_next_in_order (stmt_iter *si)
 Sets current iterator to next statement in order.

void stmt_iter_get_line_before (stmt_iter *si, int lnum)
 Sets current iterator to statement just prior to the given line number.


Function Documentation

void stmt_iter_copy stmt_iter si,
stmt_iter orig
 

Copies the given statement iterator.

Parameters:
si Pointer to statement iterator containing the copied information
orig Pointer to original statementer iterator being copied
Copies the given statement iterator to the given iterator.

00051                                                       { PROFILE(STMT_ITER_COPY);
00052 
00053   si->curr = orig->curr;
00054   si->last = orig->last;
00055 
00056   PROFILE_END;
00057 
00058 }

void stmt_iter_find_head stmt_iter si,
bool  skip
 

Sets specified iterator to start with statement head for ordering.

Parameters:
si Pointer to statement iterator to transform.
skip Specifies if we should skip to the next statement header.
Iterates down statement list until a statement head is reached. If a statement head is found, the iterator is reversed (with curr pointing to statement head). Used for displaying statements in line order for reports.

00106                                                      { PROFILE(STMT_ITER_FIND_HEAD);
00107   
00108   while( (si->curr != NULL) && ((si->curr->stmt->suppl.part.head == 0) || skip) ) {
00109     if( si->curr->stmt->suppl.part.head == 1 ) {
00110       skip = FALSE;
00111     }
00112     stmt_iter_next( si );
00113   }
00114   
00115   if( si->curr != NULL ) {
00116     stmt_iter_next( si );
00117     stmt_iter_reverse( si );
00118   }
00119 
00120   PROFILE_END;
00121   
00122 }

void stmt_iter_get_line_before stmt_iter si,
int  lnum
 

Sets current iterator to statement just prior to the given line number.

Parameters:
si Pointer to statement iterator to search
lnum Line number to compare against
Searches the given statement iterator for the statement whose line number comes just before the given line number. Places curr on this statement and places last on the statement whose line number is either equal to or less than curr.

00192                                                           { PROFILE(STMT_ITER_GET_LINE_BEFORE);
00193 
00194   if( si->curr != NULL ) {
00195 
00196     if( si->curr->stmt->ppline < lnum ) {
00197       while( (si->curr != NULL) && (si->curr->stmt->ppline < lnum) ) {
00198         stmt_iter_next( si );
00199       }
00200     } else {
00201       while( (si->curr != NULL) && (si->curr->stmt->ppline > lnum) ) {
00202         stmt_iter_next( si );
00203       }
00204     }
00205 
00206   }
00207 
00208   PROFILE_END;
00209 
00210 }

void stmt_iter_get_next_in_order stmt_iter si  ) 
 

Sets current iterator to next statement in order.

Parameters:
si Pointer to statement iterator to transform.
Iterates to next statement in list and compares this statement ID with the previous statement ID. If the new statement ID is less than the previous statement ID, we need to reverse the iterator, find the second statement head and reverse the iterator again. This function is used to order statements by line number in verbose reports.

00133                                                   { PROFILE(STMT_ITER_GET_NEXT_IN_ORDER);
00134 
00135   stmt_iter lsi;                  /* Points to lowest statement iterator */
00136   int       lowest = 0x7fffffff;  /* Line number of the lowest statement */
00137 
00138   /* If the current statement is not a head, go back to the head */
00139   if( si->curr->stmt->suppl.part.head == 0 ) {
00140     stmt_iter_reverse( si );
00141     stmt_iter_find_head( si, FALSE );
00142   }
00143 
00144   /* Capture the lowest statement iterator */
00145   lsi.curr = NULL;
00146   lsi.last = NULL;
00147 
00148   /* Advance to the next statement */
00149   stmt_iter_next( si );
00150   
00151   /* Search for a statement that has not been traversed yet within this statement block */
00152   while( (si->curr != NULL) && (si->curr->stmt->suppl.part.head == 0) ) {
00153     if( (si->curr->stmt->suppl.part.added == 0) &&
00154         (si->curr->stmt->ppline != 0) &&
00155         (si->curr->stmt->ppline < lowest) ) {
00156       lowest   = si->curr->stmt->ppline;
00157       lsi.curr = si->curr;
00158       lsi.last = si->last;
00159     }
00160     stmt_iter_next( si );
00161   }
00162 
00163   /*
00164     If we were unable to find an untraversed statement, go to the next statement block,
00165     resetting the added supplemental value as we go.
00166   */
00167   if( (lsi.curr == NULL) && (lsi.last == NULL) ) {
00168     stmt_iter_reverse( si );
00169     while( (si->curr != NULL) && (si->curr->stmt->suppl.part.head == 0) ) {
00170       si->curr->stmt->suppl.part.added = 0;
00171       stmt_iter_next( si );
00172     }
00173     stmt_iter_find_head( si, TRUE );
00174   } else {
00175     si->curr = lsi.curr;
00176     si->last = lsi.last;
00177     si->curr->stmt->suppl.part.added = 1;
00178   }
00179 
00180   PROFILE_END;
00181 
00182 }

void stmt_iter_next stmt_iter si  ) 
 

Moves to the next statement link.

Parameters:
si Pointer to statement iterator to advance.
Returns:
Returns pointer to next statement link.
Advances specified statement iterator to next statement link in statement list.

00068                                      { PROFILE(STMT_ITER_NEXT);
00069   
00070   stmt_link* tmp;    /* Temporary holder for current statement link */
00071   
00072   tmp      = si->curr;
00073   si->curr = (stmt_link*)((long int)si->curr->ptr ^ (long int)si->last);
00074   si->last = tmp;
00075 
00076   PROFILE_END;
00077   
00078 }

void stmt_iter_reset stmt_iter si,
stmt_link start
 

Resets the specified statement iterator at start point.

Parameters:
si Pointer to statement iterator to reset.
start Specifies link to start iterating through (can be head or tail).
Initializes the specified statement iterator to begin advancing.

00036                                                         { PROFILE(STMT_ITER_RESET);
00037   
00038   si->curr = start;
00039   si->last = NULL;
00040 
00041   PROFILE_END;
00042   
00043 }

void stmt_iter_reverse stmt_iter si  ) 
 

Reverses iterator flow and advances to next statement link.

Parameters:
si Pointer to statement iterator to reverse.
Reverses the direction of the iterator and changes the current pointer to point to the last statement before the reverse.

00086                                         { PROFILE(STMT_ITER_REVERSE);
00087   
00088   stmt_link* tmp;
00089   
00090   tmp      = si->curr;
00091   si->curr = si->last;
00092   si->last = tmp;
00093 
00094   PROFILE_END;
00095   
00096 }


Generated on Wed Jun 17 22:19:22 2009 for Covered by doxygen 1.3.4