next up previous contents index
Next: Comments Up: Statements Previous: Creating Fortran statements and

   
Modifying the fortran code

This set of functions allows the user to modify the fortran program. We emphasize the cut & paste concept in order to facilitate the user's operation:

  $\blacktriangleright$ CUT(t)
 
The   statement cuts the AST t and put it in the default clipboard.

  $\blacktriangleright$ PASTE(pos,src,dest)
 
The   statement inserts the AST src in the AST dest:

$\vartriangleright$ Example 38:The following program applies the transformation described in the example 39

     

  SCRIPT test()
    if_stat := $cstat 
    IF (if_stat.VARIANT!="struct_if") THEN
      ERROR(1,"Please, select a IF-THEN statement") 
    ENDIF
    PASTE("BEFORE",PARSESTAT("        print *,'before'"),if_stat) 
    PASTE(1,PARSESTAT("        print *,'start'"),if_stat.THENCLAUSE) 
    PASTE(0,PARSESTAT("        print *,'end'"),if_stat.THENCLAUSE) 
    PASTE("AFTER",PARSESTAT("        print *,'after'"),if_stat) 
  ENDSCRIPT

$\vartriangleright$ Example 39:a simple Fortran transformation 

   IF (X.EQ.10) THEN
     Y=X*2 
     CALL FOO(X,4) 
   ENDIF
$\longrightarrow$
   PRINT *,'before' 
   IF (X.EQ.10) THEN
     PRINT *,'start' 
     Y=X*2 
     CALL FOO(X,4) 
     PRINT *,'end' 
   ENDIF
   PRINT *,'after'

  $\blacktriangleright$ SWAP(t1,t2)
 
The   statement exchanges the ASTs t1 and t2.

  $\blacktriangleright$ REMOVESYMB(name)
 
The statement   removes the symbol of the current unit.

  $\blacktriangleright$ REPLACEIN(dest,new,old)
 
The statement   replaces each occurence of the AST old in the AST dest by a copy of the AST new. The example 40 shows how to rename the index of a DO statement.

$\vartriangleright$ Example 40:  Rename the index of a the DO statement given in argument.  

        SCRIPT main (dostat)
          // Get the old index
          oldindex := COPY(dostat.INDEX) 
          // The new index is "ind" 
          newindex := PARSEEXPR("ind")
           
          REPLACEIN(dostat,newindex,oldindex)
       ENDSCRIPT


next up previous contents index
Next: Comments Up: Statements Previous: Creating Fortran statements and
Yann Mevel
1999-04-30