Changeset 93c10de for src/AST/Type.hpp


Ignore:
Timestamp:
Nov 24, 2022, 11:01:37 AM (22 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, ast-experimental, master
Children:
82a90d4
Parents:
78de1e5
Message:

Minimal changes to pull out nested types, TypeInstType::TypeEnvKey? and TypeDecl::Data (now TypeData?) from there parent types. Although they do connect to the parent types they were nested in they are used on their own most of the time.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Type.hpp

    r78de1e5 r93c10de  
    1010// Created On       : Thu May 9 10:00:00 2019
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Jul 14 15:54:00 2021
    13 // Update Count     : 7
     12// Last Modified On : Thu Nov 24  9:47:00 2022
     13// Update Count     : 8
    1414//
    1515
     
    390390};
    391391
     392struct TypeEnvKey;
     393
    392394/// instance of named type alias (typedef or variable)
    393395class TypeInstType final : public BaseInstType {
     
    401403        int expr_id = 0;
    402404
    403         // compact representation used for map lookups.
    404         struct TypeEnvKey {
    405                 const TypeDecl * base = nullptr;
    406                 int formal_usage = 0;
    407                 int expr_id = 0;
    408 
    409                 TypeEnvKey() = default;
    410                 TypeEnvKey(const TypeDecl * base, int formal_usage = 0, int expr_id = 0)
    411                 : base(base), formal_usage(formal_usage), expr_id(expr_id) {}
    412                 TypeEnvKey(const TypeInstType & inst)
    413                 : base(inst.base), formal_usage(inst.formal_usage), expr_id(inst.expr_id) {}
    414                 std::string typeString() const;
    415                 bool operator==(const TypeEnvKey & other) const;
    416                 bool operator<(const TypeEnvKey & other) const;
    417         };
    418 
    419405        bool operator==(const TypeInstType & other) const;
    420406
     
    433419        TypeInstType( const TypeInstType & o ) = default;
    434420
    435         TypeInstType( const TypeEnvKey & key )
    436         : BaseInstType(key.base->name), base(key.base), kind(key.base->kind), formal_usage(key.formal_usage), expr_id(key.expr_id) {}
     421        TypeInstType( const TypeEnvKey & key );
    437422
    438423        /// sets `base`, updating `kind` correctly
     
    453438        TypeInstType * clone() const override { return new TypeInstType{ *this }; }
    454439        MUTATE_FRIEND
     440};
     441
     442/// Compact representation of TypeInstType used for map lookups.
     443struct TypeEnvKey {
     444        const TypeDecl * base = nullptr;
     445        int formal_usage = 0;
     446        int expr_id = 0;
     447
     448        TypeEnvKey() = default;
     449        TypeEnvKey(const TypeDecl * base, int formal_usage = 0, int expr_id = 0)
     450        : base(base), formal_usage(formal_usage), expr_id(expr_id) {}
     451        TypeEnvKey(const TypeInstType & inst)
     452        : base(inst.base), formal_usage(inst.formal_usage), expr_id(inst.expr_id) {}
     453        std::string typeString() const;
     454        bool operator==(const TypeEnvKey & other) const;
     455        bool operator<(const TypeEnvKey & other) const;
    455456};
    456457
     
    560561namespace std {
    561562        template<>
    562         struct hash<typename ast::TypeInstType::TypeEnvKey> {
    563                 size_t operator() (const ast::TypeInstType::TypeEnvKey & x) const {
     563        struct hash<typename ast::TypeEnvKey> {
     564                size_t operator() (const ast::TypeEnvKey & x) const {
    564565                        const size_t p = 1000007;
    565566                        size_t res = reinterpret_cast<size_t>(x.base);
Note: See TracChangeset for help on using the changeset viewer.