mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 09:11:05 +01:00
Change Declaration passing to use Ptr (#758)
This commit is contained in:
@@ -69,6 +69,7 @@
|
||||
#include "executable_semantics/ast/function_definition.h"
|
||||
#include "executable_semantics/ast/pattern.h"
|
||||
#include "executable_semantics/common/arena.h"
|
||||
#include "executable_semantics/common/ptr.h"
|
||||
#include "executable_semantics/ast/paren_contents.h"
|
||||
|
||||
namespace Carbon {
|
||||
@@ -95,7 +96,7 @@ void Carbon::Parser::error(const location_type&, const std::string& message) {
|
||||
%type <const Declaration*> declaration
|
||||
%type <const FunctionDefinition*> function_declaration
|
||||
%type <const FunctionDefinition*> function_definition
|
||||
%type <std::list<const Declaration*>> declaration_list
|
||||
%type <std::list<Ptr<const Declaration>>> declaration_list
|
||||
%type <const Statement*> statement
|
||||
%type <const Statement*> if_statement
|
||||
%type <const Statement*> optional_else
|
||||
@@ -584,11 +585,11 @@ declaration:
|
||||
;
|
||||
declaration_list:
|
||||
// Empty
|
||||
{ $$ = std::list<const Declaration*>(); }
|
||||
{ $$ = std::list<Ptr<const Declaration>>(); }
|
||||
| declaration declaration_list
|
||||
{
|
||||
$$ = $2;
|
||||
$$.push_front($1);
|
||||
$$.push_front(Ptr<const Declaration>($1));
|
||||
}
|
||||
;
|
||||
%%
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Carbon {
|
||||
|
||||
// Adds builtins, currently only Print(). Note Print() is experimental, not
|
||||
// standardized, but is made available for printing state in tests.
|
||||
static void AddIntrinsics(std::list<const Declaration*>* fs) {
|
||||
static void AddIntrinsics(std::list<Ptr<const Declaration>>* fs) {
|
||||
std::vector<TuplePattern::Field> print_fields = {TuplePattern::Field(
|
||||
"0", global_arena->RawNew<BindingPattern>(
|
||||
-1, "format_str",
|
||||
@@ -26,7 +26,7 @@ static void AddIntrinsics(std::list<const Declaration*>* fs) {
|
||||
global_arena->RawNew<IntrinsicExpression>(
|
||||
IntrinsicExpression::IntrinsicKind::Print),
|
||||
false);
|
||||
auto* print = global_arena->RawNew<FunctionDeclaration>(
|
||||
auto print = global_arena->New<FunctionDeclaration>(
|
||||
global_arena->RawNew<FunctionDefinition>(
|
||||
-1, "Print", std::vector<GenericBinding>(),
|
||||
global_arena->RawNew<TuplePattern>(-1, print_fields),
|
||||
@@ -36,11 +36,11 @@ static void AddIntrinsics(std::list<const Declaration*>* fs) {
|
||||
fs->insert(fs->begin(), print);
|
||||
}
|
||||
|
||||
void ExecProgram(std::list<const Declaration*> fs) {
|
||||
void ExecProgram(std::list<Ptr<const Declaration>> fs) {
|
||||
AddIntrinsics(&fs);
|
||||
if (tracing_output) {
|
||||
llvm::outs() << "********** source program **********\n";
|
||||
for (const auto* decl : fs) {
|
||||
for (const auto decl : fs) {
|
||||
llvm::outs() << *decl;
|
||||
}
|
||||
llvm::outs() << "********** type checking **********\n";
|
||||
@@ -49,14 +49,14 @@ void ExecProgram(std::list<const Declaration*> fs) {
|
||||
TypeCheckContext p = TopLevel(fs);
|
||||
TypeEnv top = p.types;
|
||||
Env ct_top = p.values;
|
||||
std::list<const Declaration*> new_decls;
|
||||
for (const auto* decl : fs) {
|
||||
new_decls.push_back(MakeTypeChecked(*decl, top, ct_top));
|
||||
std::list<Ptr<const Declaration>> new_decls;
|
||||
for (const auto decl : fs) {
|
||||
new_decls.push_back(MakeTypeChecked(decl, top, ct_top));
|
||||
}
|
||||
if (tracing_output) {
|
||||
llvm::outs() << "\n";
|
||||
llvm::outs() << "********** type checking complete **********\n";
|
||||
for (const auto* decl : new_decls) {
|
||||
for (const auto decl : new_decls) {
|
||||
llvm::outs() << *decl;
|
||||
}
|
||||
llvm::outs() << "********** starting execution **********\n";
|
||||
|
||||
@@ -12,11 +12,12 @@
|
||||
#include <list>
|
||||
|
||||
#include "executable_semantics/ast/declaration.h"
|
||||
#include "executable_semantics/common/ptr.h"
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
// Runs the top-level declaration list.
|
||||
void ExecProgram(std::list<const Declaration*> fs);
|
||||
void ExecProgram(std::list<Ptr<const Declaration>> fs);
|
||||
|
||||
} // namespace Carbon
|
||||
|
||||
|
||||
Reference in New Issue
Block a user