Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Decl.cpp

    ra300e4a r2bb4a01  
    1414//
    1515
    16 #include <cassert>        // for assert, strict_dynamic_cast
    1716#include <unordered_map>
    1817
    1918#include "Decl.hpp"
    2019
    21 #include "Fwd.hpp"        // for UniqueId
    22 #include "Init.hpp"
    23 #include "Node.hpp"       // for readonly
     20#include "Fwd.hpp"   // for UniqueId
     21#include "Node.hpp"  // for readonly
    2422
    2523namespace ast {
    26 
    2724// To canonicalize declarations
    2825static UniqueId lastUniqueId = 0;
     
    4239        return {};
    4340}
    44 
    45 // --- EnumDecl
    46 
    47 bool EnumDecl::valueOf( Decl* enumerator, long long& value ) const {
    48         if ( enumValues.empty() ) {
    49                 long long crntVal = 0;
    50                 for ( const Decl* member : members ) {
    51                         const ObjectDecl* field = strict_dynamic_cast< const ObjectDecl* >( member );
    52                         if ( field->init ) {
    53                                 const SingleInit* init = strict_dynamic_cast< const SingleInit* >( field->init );
    54                                 auto result = eval( init->value );
    55                                 if ( ! result.second ) {
    56                                         SemanticError( init->location, toString( "Non-constexpr in initialization of "
    57                                                 "enumerator: ", field ) );
    58                                 }
    59                                 crntVal = result.first;
    60                         }
    61                         if ( enumValues.count( field->name ) != 0 ) {
    62                                 SemanticError( location, toString( "Enum ", name, " has multiple members with the "     "name ", field->name ) );
    63                         }
    64                         enumValues[ field->name ] = crntVal;
    65                         ++crntVal;
    66                 }
    67         }
    68 
    69         auto it = enumValues.find( enumerator->name );
    70         if ( it != enumValues.end() ) {
    71                 value = it->second;
    72                 return true;
    73         }
    74         return false;
    75 }
    76 
    7741}
    7842
Note: See TracChangeset for help on using the changeset viewer.