Any dervish routine that takes a handle as an input can also take a handle expression.
Example: if h17 is a handle to a REGION, then h17.nrow is a handle to an INT which the the number of rows in that region.
The function calls to access the parser are:
int shTclHandleExprEval(interp, line, &handle, &userPtr)
where line is the input character string, handle is user-supplied storage to store the output handle structure, and userPtr is user-supplied storage for certain exceptional cases. The exceptional cases arise in the following 2 instances. Suppose h22 is a pointer to a structure as follows:
typedef struct { int array[10]; } EXAMPLE;then the expressions &h22 returns a handle to a pointer to a structure of type EXAMPLE, and h22.array return a handle to a pointer to an array of INT's. In both cases, extra storage is needed to hold the actual pointer. This storage is supplied by the user in userPtr. The calling routine is responsible for making sure that this storage is persistent if the returned handle structure is to remain valid outside the scope of the calling routine (e.g., if the result of the handle expression is explictly bound to a new handle, then userPtr should be shMalloc'ed by the calling routine.)
The grammar for expressions is:
expr : term | * expr | & expr | (type) term term : primary | term . WORD | term -> WORD | term < INTEGER > | term [ INTEGER ] primary : WORD | ( expr ) | exprThis results in the normal C precedence and associativity for these operators.
There is a problem, in that a ( in expr can be a (cast) or an (expr); this is handled by looking to see if the first token in the parentheses is a known type.
The expressions are evaluated by means of a recursive descent parser.
DESCRIPTION: evaluate an expression involving a handle, *, &, ., ->, [] or <>, and (). RETURN VALUES: TCL_OK: operation is a success. TCL_ERROR: could not evaluate correctly the expression in address_out: the address pointed by the handle expression in sch_elm: a complete 'description' of what is the result of the handle expression. This is usefull since the handle types are slightly poor in Dervish. in out_type: the underlined type. (this is equivalent to the type described in sch_elm->type but expressed in integer value) SIGNATURE: RET_CODE shTclHandleExprEvalWithInfo( Tcl_Interp *iinterp, /* IN: the TCL interpreter */ char *line, /* IN: expression to be evaluated */ char **address_out, /* OUT: return address */ SCHEMA_ELEM *sch_elm,/* OUT: contain type information */ int *out_type /* final type */ )