// TO DO: Currently labels assume a flat namespace.  Need to make them obey scoping rules.
// Only one occurence of any one label per block?  Or per procedure? - no best solution is
// to replace user labels with generated labels.

// ALSO... *BIG* todo ... C has several name spaces for different kinds of objects -
// variables, labels, typedefs, struct names, etc.  Need to get definitive list, and
// provide interfaces to look up each individually.

// struct, union & enum share a namespace. (http://web.torek.net/torek/c/types2.html)

// Pull name and result typeinfo out of
// P<declaration> = <struct-decl> |
//                  <scalar-decl> |
//                  <proc-fn-decl> |
//                  <array-decl>;
// - this will be a single unit of one of the above, not a list of them
// Depends on how grammar.c currently implements the phrases above, which
// at some point may be unified via a new cleaner AST_Declare operator.

// would prefer a single fn with 2 results.  Should really make them into
// two "int *" out parameters

int DeclName(int declp) {
  for (;;) {
    switch (astop(declp)) {
      case AST_SEQ:
        declp = leftchild(declp);
        break;
      case AST_Declare:
        return leftchild(declp);
//    case AST_TYPE_Struct:
//      return -1;
      default:
        fprintf(stderr, "* Internal Error: missing case %d: in DeclName\n", astop(declp));
  //    fprintf(stderr, "* Internal Error: missing case %s: in DeclName\n", op[astop(declp)].Diag_Name);
        return -1;
    }
  }
}

int DeclType(int declp) {
  for (;;) {
    switch (astop(declp)) {
      case AST_SEQ:
        declp = leftchild(declp);
        break;
      case AST_Declare:
        return rightchild(declp);
//    case AST_TYPE_Struct:
//      return -1;
      default:
        fprintf(stderr, "* Internal Error: missing case %d: in DeclType\n", astop(declp));
   //   fprintf(stderr, "* Internal Error: missing case %s: in DeclType\n", op[astop(declp)].Diag_Name);
        return -1;
    }
  }
}
