mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-30 12:25:03 +01:00
Adds basic support for class functions and methods. (#1057)
* adding methods to the ast * pre commit stuff? * implementation of class functions * implemented methods * some cleanup * more cleanup * add newlines in test programs * pre-commit fixups * added include of return_term.h * a test of a method calling another method * replacing Member with Declaration * removing the member.h etc files * clarify a type annotation * update uses of FunctionDeclaration * remove ReturnTarget, no longer needed * more cleanup * more cleanup * yet more cleanup, playing with pre-commit * did a pre-commit run --all-files * fixed const issue * remove comment * checking dependencies in BUILD files and headers * pre-commit working now * refactor NominalClassType to just hold a pointer to the class declaration * remove Member from rtti * responding to Geoffreys review * change field_types to a non-member function
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include "executable_semantics/interpreter/resolve_control_flow.h"
|
||||
|
||||
#include "executable_semantics/ast/declaration.h"
|
||||
#include "executable_semantics/ast/return_term.h"
|
||||
#include "executable_semantics/ast/statement.h"
|
||||
#include "executable_semantics/common/error.h"
|
||||
#include "llvm/Support/Casting.h"
|
||||
@@ -110,16 +111,32 @@ static void ResolveControlFlow(Nonnull<Statement*> statement,
|
||||
}
|
||||
}
|
||||
|
||||
void ResolveControlFlow(Nonnull<Declaration*> declaration) {
|
||||
switch (declaration->kind()) {
|
||||
case DeclarationKind::FunctionDeclaration: {
|
||||
auto& function = cast<FunctionDeclaration>(*declaration);
|
||||
if (function.body().has_value()) {
|
||||
FunctionData data = {.declaration = &function};
|
||||
ResolveControlFlow(*function.body(), std::nullopt, &data);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case DeclarationKind::ClassDeclaration: {
|
||||
auto& class_decl = cast<ClassDeclaration>(*declaration);
|
||||
for (Nonnull<Declaration*> member : class_decl.members()) {
|
||||
ResolveControlFlow(member);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// do nothing
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ResolveControlFlow(AST& ast) {
|
||||
for (auto declaration : ast.declarations) {
|
||||
if (declaration->kind() != DeclarationKind::FunctionDeclaration) {
|
||||
continue;
|
||||
}
|
||||
auto& function = cast<FunctionDeclaration>(*declaration);
|
||||
if (function.body().has_value()) {
|
||||
FunctionData data = {.declaration = &function};
|
||||
ResolveControlFlow(*function.body(), std::nullopt, &data);
|
||||
}
|
||||
ResolveControlFlow(declaration);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user