next up previous contents index
Next: Attributes for expressions Up: Various attributes and functions Previous: Attributes for unit

Objects names and constant strings

Many Fortran constructs such as variables, functions, subroutines have a name. It is coded by a node of variant "name".

  $\blacktriangleright$ t.IDENT
 
  The expression returns the node of variant "name" associated to the AST t. If this node does not exist, then the expression returns FALSE.
  $\blacktriangleright$ t.SYMBOL
 
The expression   returns a string that contains the symbol associated to the result of t.IDENT. This is a shortcut to t.IDENT.TOSTRING.
  $\blacktriangleright$ t.SNAME
 
The expression   returns the result of t.IDENT as a node of variant "fstring_cst" i.e. a fortran constant string). This is a shortcut to
CREATEVALUED("fstring_cst",t.IDENT.TOSTRING)

$\vartriangleright$ Example 47:Insert a PRINT statement before a scalar assignment.

         

  SCRIPT addprint ()
    stat := $cstat
    // Test an assignment
    ok := FALSE
    IF (stat.VARIANT == "ass") THEN
      dest:=stat.LHS 
      // Test if there is a "name" node
      // associated to the destination 
      // expression (allways ?) . 
      IF (dest.IDENT) THEN
        name_as_symbol := dest.SYMBOL 
        name_as_fstring := dest.SNAME 
        name_as_var := COPY(dest.IDENT)
        // Check that the variable is declared 
        // as a scalar
        IF (name_as_symbol.DIMENSION==0) THEN
          cmd1 := "         print *,'The variable',%e,'is assigned'"
          newstat1 := PARSESTAT(cmd1,name_as_fstring)
          cmd2 := "         print *,'It old value was ',%e"
          newstat2 := PARSESTAT(cmd2,name_as_var)
          PASTE("BEFORE",newstat1,stat)
          PASTE("BEFORE",newstat2,stat)
          ok:=TRUE
        ENDIF
      ENDIF
    ENDIF
    IF (! ok) THEN
      ERROR(1,"Please, select an assignment 'scalar:=expression'")
    ENDIF 
  ENDSCRIPT



Yann Mevel
1999-04-30