Implement static name resolution (#958)

This doesn't actually use the results of name resolution, but it does verify that they are present.
Also ensures that name resolution and type checking are applied to deduced function parameters and the implicit call to `Main()`.

Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
This commit is contained in:
Geoff Romer
2021-11-30 13:33:54 -08:00
committed by GitHub
co-authored by Jon Meow
parent dc5e62fc7a
commit 17e0a1afb9
12 changed files with 347 additions and 22 deletions
+18
View File
@@ -21,6 +21,7 @@
namespace Carbon {
class Value;
class NamedEntity;
class Expression : public virtual AstNode {
public:
@@ -129,8 +130,25 @@ class IdentifierExpression : public Expression {
auto name() const -> const std::string& { return name_; }
// Returns the NamedEntity this identifier refers to. Cannot be called before
// name resolution.
auto named_entity() const -> const NamedEntity& { return **named_entity_; }
// Sets the value returned by named_entity. Can be called only once,
// during name resolution.
void set_named_entity(Nonnull<const NamedEntity*> named_entity) {
CHECK(!named_entity_.has_value());
named_entity_ = named_entity;
}
// Returns true if set_named_entity has been called. Should be used only
// for debugging purposes.
// TODO: remove this once we no longer need the CHECKs that use it.
auto has_named_entity() const -> bool { return named_entity_.has_value(); }
private:
std::string name_;
std::optional<Nonnull<const NamedEntity*>> named_entity_;
};
class FieldAccessExpression : public Expression {