Ejemplo n.º 1
0
// Parse a destructor-id. A destuctor-id naems the destructor of
// a class or a decltype-type that refers to a class.
//
//    destructor-id:
//      '~' class-name
//      '~' decltype-type
Name&
Parser::destructor_id()
{
  Token tok = match(tilde_tok);
  if (lookahead() == decltype_tok) {
    Type& t = decltype_type();
    return on_destructor_id(tok, t);
  } else {
    Type& t = class_name();
    return on_destructor_id(tok, t);
  }
}
Ejemplo n.º 2
0
// Parse a primary type.
//
//    primary-type:
//      'void'
//      'byte'
//      'bool'
//      'char'
//      'int'
//      'float'
//      'auto'
//      id-type
//      decltype-type
//      function-type
//      '( unary-type )'
//      '{ type-list }'
//
// FIXME: Design a better integer and FP type suite.
Type&
Parser::primary_type()
{
  switch (lookahead()) {
    case void_tok:
      return on_void_type(accept());
    case bool_tok:
      return on_bool_type(accept());
    case int_tok:
      return on_int_type(accept());
    case byte_tok:
      return on_byte_type(accept());

    // TODO: Implement me.
    case char_tok:
      lingo_unimplemented("char type");
    
    case float_tok:
      lingo_unimplemented("float type");
    
    case auto_tok:
      lingo_unimplemented("auto type");
    
    case decltype_tok:
      return decltype_type();

    case class_tok:
      return on_class_type(accept());

    case coroutine_tok:
      return on_coroutine_type(accept());

    case lparen_tok: {
      // FIXME: We shouldn't need a tentative parse for this.
      if (Type* t = match_if(&Parser::function_type))
        return *t;
      return grouped_type();
    }
    
    case lbrace_tok:
      return tuple_type();

    default:
      return id_type();
  }
}
Ejemplo n.º 3
0
// Parse a leading-name-specifier. This defines the set of
// terms that can be nested within a nested-name-specifier.
//
//    nested-name-specifier:
//      '::'
//      namespace-name '::'
//      type-name '::'
//      decltype-type '::'
Decl&
Parser::leading_name_specifier()
{
  Decl* scope;
  if (lookahead() == colon_colon_tok)
    scope = &on_nested_name_specifier();
  else if (lookahead() == decltype_tok)
    scope = &on_nested_name_specifier(decltype_type());
  else if (Decl* n = match_if(&Parser::namespace_name))
    scope = &on_nested_name_specifier(*n);
  else if (Type* t = match_if(&Parser::type_name))
    scope = &on_nested_name_specifier(*t);
  else
    throw Syntax_error("expected leading-name-specifier");
  match(colon_colon_tok);
  return *scope;
}