gcc config
[prop.git] / prop-src / ast.pcc
blob6ba7db20557f80decda3ab388902e3262ff3169f
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 //  This file implements some basic AST manipulation routines
4 //
5 ///////////////////////////////////////////////////////////////////////////////
6 #include <stdlib.h>
7 #include "basics.ph"
8 #include "ast.ph"
10 ///////////////////////////////////////////////////////////////////////////////
12 //  Select the ith component from an expression list
14 ///////////////////////////////////////////////////////////////////////////////
15 Exp component_exp(Exps exps, int n)
16 {  Exps es = exps;
17    int  i  = n;
18    match while (es)
19    {  #[h ... _] | i == 1: { return h; }
20    |  #[_ ... t]:          { es = t; i--; }
21    }
22    error("%Lexpression %e does not have component %i\n",
23          TUPLEexp(exps), n);
24    return NOexp;
27 ///////////////////////////////////////////////////////////////////////////////
29 //  Select the ith component from an expression list
31 ///////////////////////////////////////////////////////////////////////////////
32 Exp component_exp(Exps exps, Id n)
33 {  return component_exp(exps,atol(n+1)); }
35 ///////////////////////////////////////////////////////////////////////////////
37 //  Select the ith component from a labeled expression list
39 ///////////////////////////////////////////////////////////////////////////////
40 Exp component_exp(LabExps labeled_exps, Id n)
41 {  LabExps les = labeled_exps;
42    match while (les)
43    {  #[ {label, exp} ... _] | label == n: { return exp; }
44    |  #[ _ ... t]: { les = t; }
45    }
46    error("%Lexpression %e does not have component %s\n",
47          RECORDexp(labeled_exps), n);
48    return NOexp;