Changeset c7ebbec


Ignore:
Timestamp:
Dec 21, 2023, 10:21:28 AM (12 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
master
Children:
116d7e2
Parents:
523e300
Message:

Reorganization of Linkage::Spec. is_mangled represented two properties with is_gcc_builtin separating them in one case. The second property is_overloadable which replaces is_gcc_builtin.

Location:
src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/AST/LinkageSpec.cpp

    r523e300 rc7ebbec  
    2727namespace Linkage {
    2828
    29 Spec update( CodeLocation loc, Spec spec, const std::string * cmd ) {
     29Spec update( const CodeLocation & loc, Spec spec, const std::string * cmd ) {
    3030        assert( cmd );
    3131        std::unique_ptr<const std::string> guard( cmd ); // allocated by lexer
    3232        if ( *cmd == "\"Cforall\"" ) {
    33                 spec.is_mangled = true;
    34                 return spec;
     33                spec.is_mangled = spec.is_overloadable = true;
    3534        } else if ( *cmd == "\"C\"" ) {
    36                 spec.is_mangled = false;
    37                 return spec;
     35                spec.is_mangled = spec.is_overloadable = false;
    3836        } else {
    3937                SemanticError( loc, "Invalid linkage specifier %s", cmd->c_str() );
    4038        }
     39        return spec;
    4140}
    4241
  • src/AST/LinkageSpec.hpp

    r523e300 rc7ebbec  
    3131        Overrideable = 1 << 2,
    3232        Builtin      = 1 << 3,
    33         GccBuiltin   = 1 << 4
     33        Overloadable = 1 << 4,
    3434};
    3535
     
    4343                        bool is_overrideable : 1;
    4444                        bool is_builtin      : 1;
    45                         bool is_gcc_builtin : 1;
     45                        bool is_overloadable : 1;
    4646                };
    4747        };
     
    5252using Spec = bitfield<spec_flags>;
    5353
    54 /// If `cmd` = "C" returns `spec` with `is_mangled = false`.
    55 /// If `cmd` = "Cforall" returns `spec` with `is_mangled = true`.
    56 Spec update( CodeLocation loc, Spec spec, const std::string * cmd );
     54/// Updates `spec` based on `cmd` (should be "C" or "Cforall").
     55Spec update( const CodeLocation & loc, Spec spec, const std::string * cmd );
    5756
    5857/// A human-readable name for this spec
     
    6261
    6362/// C built-in defined in prelude
    64 constexpr Spec Intrinsic  = { Mangle | Generate | Overrideable | Builtin };
     63constexpr Spec Intrinsic  = { Mangle | Generate | Overrideable | Builtin | Overloadable };
    6564/// Ordinary Cforall
    66 constexpr Spec Cforall    = { Mangle | Generate };
     65constexpr Spec Cforall    = { Mangle | Generate | Overloadable };
    6766/// C code: not overloadable, not mangled
    6867constexpr Spec C          = { Generate };
    6968/// Built by translator (e.g. struct assignment)
    70 constexpr Spec AutoGen    = { Mangle | Generate | Overrideable };
     69constexpr Spec AutoGen    = { Mangle | Generate | Overrideable | Overloadable };
    7170/// GCC internal
    72 constexpr Spec Compiler   = { Mangle | Builtin | GccBuiltin };
     71constexpr Spec Compiler   = { Builtin | Overloadable };
    7372/// Mangled builtins
    74 constexpr Spec BuiltinCFA = { Mangle | Generate | Builtin };
     73constexpr Spec BuiltinCFA = { Mangle | Generate | Builtin | Overloadable };
    7574/// Non-mangled builtins
    7675constexpr Spec BuiltinC   = { Generate | Builtin };
  • src/AST/SymbolTable.cpp

    r523e300 rc7ebbec  
    644644                // new definition shadows the autogenerated one, even at the same scope
    645645                return false;
    646         } else if ( existing.id->linkage.is_mangled
     646        } else if ( existing.id->linkage.is_overloadable
    647647                        || ResolvExpr::typesCompatible(
    648648                                added->get_type(), existing.id->get_type() ) ) {
     
    719719        // this ensures that no two declarations with the same unmangled name at the same scope
    720720        // both have C linkage
    721         if ( decl->linkage.is_mangled ) {
     721        if ( decl->linkage.is_overloadable ) {
    722722                // Check that a Cforall declaration doesn't override any C declaration
    723723                if ( hasCompatibleCDecl( name, mangleName ) ) {
     
    812812                if ( decl.second.scope != scope ) continue;
    813813                // check for C decl with compatible type (by mangleName)
    814                 if ( ! decl.second.id->linkage.is_mangled && decl.first == mangleName ) return true;
     814                if ( !decl.second.id->linkage.is_overloadable && decl.first == mangleName ) return true;
    815815        }
    816816
     
    829829                if ( decl.second.scope != scope ) continue;
    830830                // check for C decl with incompatible type (by manglename)
    831                 if ( ! decl.second.id->linkage.is_mangled && decl.first != mangleName ) return true;
     831                if ( !decl.second.id->linkage.is_overloadable && decl.first != mangleName ) return true;
    832832        }
    833833
  • src/CodeGen/CodeGenerator.cpp

    r523e300 rc7ebbec  
    102102
    103103std::string CodeGenerator::mangleName( ast::DeclWithType const * decl ) {
    104         // GCC builtins should always be printed unmangled.
    105         if ( options.pretty || decl->linkage.is_gcc_builtin ) {
    106                 return decl->name;
    107         } else if ( decl->linkage.is_mangled && decl->mangleName != "" ) {
     104        if ( !options.pretty && decl->linkage.is_mangled && decl->mangleName != "" ) {
    108105                return decl->scopedMangleName();
    109106        } else {
Note: See TracChangeset for help on using the changeset viewer.