Changeset 7030dab for src/AST/Decl.cpp


Ignore:
Timestamp:
Apr 6, 2020, 4:46:28 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
e3bc51c
Parents:
71d6bd8 (diff), 057298e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into new-ast

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Decl.cpp

    r71d6bd8 r7030dab  
    99// Author           : Aaron B. Moss
    1010// Created On       : Thu May 9 10:00:00 2019
    11 // Last Modified By : Aaron B. Moss
    12 // Last Modified On : Thu May 9 10:00:00 2019
    13 // Update Count     : 1
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Dec 13 16:23:15 2019
     13// Update Count     : 20
    1414//
    1515
     
    1818#include <cassert>             // for assert, strict_dynamic_cast
    1919#include <iostream>
    20 #include <string>
    2120#include <unordered_map>
    2221
     
    2726#include "Node.hpp"            // for readonly
    2827#include "Type.hpp"            // for readonly
    29 #include "Parser/ParseNode.h"  // for DeclarationNode
    3028
    3129namespace ast {
     
    5856// --- TypeDecl
    5957
    60 std::string TypeDecl::typeString() const {
    61         static const std::string kindNames[] = { "object type", "function type", "tuple type" };
    62         assertf( sizeof(kindNames)/sizeof(kindNames[0]) == DeclarationNode::NoTypeClass-1,
    63                 "typeString: kindNames is out of sync." );
    64         assertf( kind < sizeof(kindNames)/sizeof(kindNames[0]), "TypeDecl's kind is out of bounds." );
    65         return (sized ? "sized " : "") + kindNames[ kind ];
     58const char * TypeDecl::typeString() const {
     59        static const char * kindNames[] = { "sized data type", "sized object type", "sized function type", "sized tuple type" };
     60        static_assert( sizeof(kindNames)/sizeof(kindNames[0]) == TypeDecl::NUMBER_OF_KINDS, "typeString: kindNames is out of sync." );
     61        assertf( kind < TypeDecl::NUMBER_OF_KINDS, "TypeDecl kind is out of bounds." );
     62        return sized ? kindNames[ kind ] : &kindNames[ kind ][ sizeof("sized") ]; // sizeof includes '\0'
    6663}
    6764
    68 std::string TypeDecl::genTypeString() const {
    69         static const std::string kindNames[] = { "dtype", "ftype", "ttype" };
    70         assertf( sizeof(kindNames)/sizeof(kindNames[0]) == DeclarationNode::NoTypeClass-1, "genTypeString: kindNames is out of sync." );
    71         assertf( kind < sizeof(kindNames)/sizeof(kindNames[0]), "TypeDecl's kind is out of bounds." );
     65const char * TypeDecl::genTypeString() const {
     66        static const char * kindNames[] = { "dtype", "otype", "ftype", "ttype" };
     67        static_assert( sizeof(kindNames)/sizeof(kindNames[0]) == TypeDecl::NUMBER_OF_KINDS, "genTypeString: kindNames is out of sync." );
     68        assertf( kind < TypeDecl::NUMBER_OF_KINDS, "TypeDecl kind is out of bounds." );
    7269        return kindNames[ kind ];
    7370}
     
    7572std::ostream & operator<< ( std::ostream & out, const TypeDecl::Data & data ) {
    7673        return out << data.kind << ", " << data.isComplete;
     74}
     75
     76// --- AggregateDecl
     77
     78// These must harmonize with the corresponding AggregateDecl::Aggregate enumerations.
     79static const char * aggregateNames[] = { "struct", "union", "enum", "exception", "trait", "generator", "coroutine", "monitor", "thread", "NoAggregateName" };
     80
     81const char * AggregateDecl::aggrString( AggregateDecl::Aggregate aggr ) {
     82        return aggregateNames[aggr];
    7783}
    7884
Note: See TracChangeset for help on using the changeset viewer.