mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-28 16:24:53 +01:00
First change towards re-implementing interfaces using the new parser. I kept it small to make sure we are on the same page regarding stack states and how the parse tree should look like. Co-authored-by: ergawy <kareem.ergawy@guardsquare.com>
124 lines
5.9 KiB
Modula-2
124 lines
5.9 KiB
Modula-2
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
// Note that this is an X-macro header.
|
|
//
|
|
// It does not use `#include` guards, and instead is designed to be `#include`ed
|
|
// after the x-macro is defined in order for its inclusion to expand to the
|
|
// desired output.
|
|
//
|
|
// x-macros come in three forms:
|
|
// CARBON_PARSE_NODE_KIND(Name)
|
|
// Used as a fallback if other macros are missing.
|
|
// CARBON_PARSE_NODE_KIND_BRACKET(Name, BracketName)
|
|
// Defines a bracketed node kind. BracketName should refer to the node kind
|
|
// that is the _start_ of the bracketed range.
|
|
// CARBON_PARSE_NODE_KIND_CHILD_COUNT(Name, ChildCount)
|
|
// Defines a parse node with a set number of children, often 0. This count
|
|
// must be correct even when the node contains errors.
|
|
//
|
|
// Macro definitions will be removed at the end of this file to clean up.
|
|
//
|
|
// TODO: Using CHILD_COUNT(..., TodoFixParseNode) to indicate nodes which need to be fixed,
|
|
// sometimes due to inconsistent output in error modes. This is also handled in
|
|
// ParseNodeKind::child_count() and ParseTree::Verify(). All of that can be
|
|
// cleaned up once remainining nodes are fixed.
|
|
|
|
#if !(defined(CARBON_PARSE_NODE_KIND) || \
|
|
(defined(CARBON_PARSE_NODE_KIND_BRACKET) && \
|
|
defined(CARBON_PARSE_NODE_KIND_CHILD_COUNT)))
|
|
#error "Must define CARBON_PARSE_NODE_KIND family x-macros to use this file."
|
|
#endif
|
|
|
|
// The BRACKET and CHILD_COUNT macros will use CARBON_PARSE_NODE_KIND by default
|
|
// when undefined.
|
|
#ifndef CARBON_PARSE_NODE_KIND_BRACKET
|
|
#define CARBON_PARSE_NODE_KIND_BRACKET(Name, ...) CARBON_PARSE_NODE_KIND(Name)
|
|
#endif
|
|
#ifndef CARBON_PARSE_NODE_KIND_CHILD_COUNT
|
|
#define CARBON_PARSE_NODE_KIND_CHILD_COUNT(Name, ...) \
|
|
CARBON_PARSE_NODE_KIND(Name)
|
|
#endif
|
|
|
|
// Declarations.
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(DeclarationEnd, 0)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(EmptyDeclaration, 0)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(DeclaredName, 0)
|
|
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(PackageDirective, TodoFixParseNode)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(PackageApi, 0)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(PackageImpl, 0)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(PackageLibrary, 1)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(PackageEnd, 0)
|
|
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(FunctionIntroducer, 0)
|
|
CARBON_PARSE_NODE_KIND_BRACKET(FunctionDeclaration, FunctionIntroducer)
|
|
CARBON_PARSE_NODE_KIND_BRACKET(FunctionDefinition, FunctionDefinitionStart)
|
|
CARBON_PARSE_NODE_KIND_BRACKET(FunctionDefinitionStart, FunctionIntroducer)
|
|
CARBON_PARSE_NODE_KIND_BRACKET(ParameterList, ParameterListStart)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(ParameterListStart, 0)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(ParameterListComma, 0)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(PatternBinding, 2)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(ReturnType, 1)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(VariableDeclaration, TodoFixParseNode)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(VariableInitializer, 1)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(FileEnd, 0)
|
|
|
|
// Statements.
|
|
CARBON_PARSE_NODE_KIND_BRACKET(CodeBlock, CodeBlockStart)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(CodeBlockStart, 0)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(ExpressionStatement, 1)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(IfStatement, TodoFixParseNode)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(IfStatementElse, 0)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(WhileStatement, TodoFixParseNode)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(Condition, TodoFixParseNode)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(ConditionEnd, 0)
|
|
CARBON_PARSE_NODE_KIND_BRACKET(ContinueStatement, ContinueStatementStart)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(ContinueStatementStart, 0)
|
|
CARBON_PARSE_NODE_KIND_BRACKET(BreakStatement, BreakStatementStart)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(BreakStatementStart, 0)
|
|
CARBON_PARSE_NODE_KIND_BRACKET(ReturnStatement, ReturnStatementStart)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(ReturnStatementStart, 0)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(ForStatement, TodoFixParseNode)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(ForHeader, TodoFixParseNode)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(ForHeaderEnd, 0)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(ForIn, 0)
|
|
|
|
// Expressions.
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(Literal, 0)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(TupleLiteral, TodoFixParseNode)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(TupleLiteralComma, 0)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(TupleLiteralEnd, 0)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(NameReference, 0)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(ParenExpression, TodoFixParseNode)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(ParenExpressionEnd, 0)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(DesignatorExpression, TodoFixParseNode)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(DesignatedName, 0)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(CallExpression, TodoFixParseNode)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(CallExpressionComma, 0)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(CallExpressionEnd, 0)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(PrefixOperator, 1)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(InfixOperator, 2)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(PostfixOperator, 1)
|
|
|
|
// Struct literals.
|
|
CARBON_PARSE_NODE_KIND_BRACKET(StructLiteral,
|
|
StructLiteralOrStructTypeLiteralStart)
|
|
CARBON_PARSE_NODE_KIND_BRACKET(StructTypeLiteral,
|
|
StructLiteralOrStructTypeLiteralStart)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(StructLiteralOrStructTypeLiteralStart, 0)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(StructFieldDesignator, TodoFixParseNode)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(StructFieldValue, TodoFixParseNode)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(StructFieldType, TodoFixParseNode)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(StructComma, 0)
|
|
|
|
// Interfaces
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(InterfaceDefinition, TodoFixParseNode)
|
|
CARBON_PARSE_NODE_KIND_CHILD_COUNT(InterfaceBodyStart, 0)
|
|
CARBON_PARSE_NODE_KIND_BRACKET(InterfaceBody, InterfaceBodyStart)
|
|
|
|
#undef CARBON_PARSE_NODE_KIND
|
|
#undef CARBON_PARSE_NODE_KIND_BRACKET
|
|
#undef CARBON_PARSE_NODE_KIND_CHILD_COUNT
|