Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Decl.cpp

    r07de76b re0e9a0b  
    99// Author           : Aaron B. Moss
    1010// Created On       : Thu May 9 10:00:00 2019
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Dec 13 16:23:15 2019
    13 // Update Count     : 20
     11// Last Modified By : Aaron B. Moss
     12// Last Modified On : Thu May 9 10:00:00 2019
     13// Update Count     : 1
    1414//
    1515
     
    1818#include <cassert>             // for assert, strict_dynamic_cast
    1919#include <iostream>
     20#include <string>
    2021#include <unordered_map>
    2122
     
    2627#include "Node.hpp"            // for readonly
    2728#include "Type.hpp"            // for readonly
     29#include "Parser/ParseNode.h"  // for DeclarationNode
    2830
    2931namespace ast {
     
    5052
    5153const Type * FunctionDecl::get_type() const { return type.get(); }
    52 void FunctionDecl::set_type(Type * t) { type = strict_dynamic_cast< FunctionType* >( t ); }
     54void FunctionDecl::set_type( const Type * t ) {
     55        type = strict_dynamic_cast< const FunctionType * >( t );
     56}
    5357
    5458// --- TypeDecl
    5559
    56 const char * TypeDecl::typeString() const {
    57         static const char * kindNames[] = { "sized data type", "sized object type", "sized function type", "sized tuple type" };
    58         static_assert( sizeof(kindNames)/sizeof(kindNames[0]) == TypeDecl::NUMBER_OF_KINDS, "typeString: kindNames is out of sync." );
    59         assertf( kind < TypeDecl::NUMBER_OF_KINDS, "TypeDecl kind is out of bounds." );
    60         return sized ? kindNames[ kind ] : &kindNames[ kind ][ sizeof("sized") ]; // sizeof includes '\0'
     60std::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 ];
    6166}
    6267
    63 const char * TypeDecl::genTypeString() const {
    64         static const char * kindNames[] = { "dtype", "otype", "ftype", "ttype" };
    65         static_assert( sizeof(kindNames)/sizeof(kindNames[0]) == TypeDecl::NUMBER_OF_KINDS, "genTypeString: kindNames is out of sync." );
    66         assertf( kind < TypeDecl::NUMBER_OF_KINDS, "TypeDecl kind is out of bounds." );
     68std::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." );
    6772        return kindNames[ kind ];
    6873}
     
    7075std::ostream & operator<< ( std::ostream & out, const TypeDecl::Data & data ) {
    7176        return out << data.kind << ", " << data.isComplete;
    72 }
    73 
    74 // --- AggregateDecl
    75 
    76 // These must harmonize with the corresponding AggregateDecl::Aggregate enumerations.
    77 static const char * aggregateNames[] = { "struct", "union", "enum", "exception", "trait", "generator", "coroutine", "monitor", "thread", "NoAggregateName" };
    78 
    79 const char * AggregateDecl::aggrString( AggregateDecl::Aggregate aggr ) {
    80         return aggregateNames[aggr];
    8177}
    8278
Note: See TracChangeset for help on using the changeset viewer.