Changeset 1cdfa82 for src/Common


Ignore:
Timestamp:
Apr 25, 2018, 4:55:53 PM (6 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
new-env, with_gc
Children:
42107b4
Parents:
2efe4b8 (diff), 9d5fb67 (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 remote-tracking branch 'origin/master' into with_gc

Location:
src/Common
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • src/Common/Debug.h

    r2efe4b8 r1cdfa82  
    2828namespace Debug {
    2929        /// debug codegen a translation unit
    30         static inline void codeGen( __attribute__((unused)) const std::list< Declaration * > & translationUnit, __attribute__((unused)) const std::string & label ) {
     30        static inline void codeGen( __attribute__((unused)) const std::list< Declaration * > & translationUnit, __attribute__((unused)) const std::string & label, __attribute__((unused)) LinkageSpec::Spec linkageFilter = LinkageSpec::Compiler ) {
    3131        #ifdef DEBUG
    3232                std::list< Declaration * > decls;
    3333
    34                 filter( translationUnit.begin(), translationUnit.end(), back_inserter( decls ), []( Declaration * decl ) {
    35                         return ! LinkageSpec::isBuiltin( decl->get_linkage() );
     34                filter( translationUnit.begin(), translationUnit.end(), back_inserter( decls ), [linkageFilter]( Declaration * decl ) {
     35                        return ! (decl->linkage & linkageFilter);
    3636                });
    3737
    3838                std::cerr << "======" << label << "======" << std::endl;
    39                 CodeGen::generate( decls, std::cerr, false, true );
     39                CodeGen::generate(
     40                        decls,
     41                        std::cerr,
     42                        true /* doIntrinsics */,
     43                        true /* pretty */,
     44                        false /* generateC */,
     45                        false /* lineMarks */,
     46                        true /* printTypeExpr */
     47                );
    4048        #endif
    4149        } // dump
    4250
    43         static inline void treeDump( __attribute__((unused)) const std::list< Declaration * > & translationUnit, __attribute__((unused)) const std::string & label ) {
     51        static inline void treeDump( __attribute__((unused)) const std::list< Declaration * > & translationUnit, __attribute__((unused)) const std::string & label, __attribute__((unused)) LinkageSpec::Spec linkageFilter = LinkageSpec::Compiler ) {
    4452        #ifdef DEBUG
    4553                std::list< Declaration * > decls;
    4654
    47                 filter( translationUnit.begin(), translationUnit.end(), back_inserter( decls ), []( Declaration * decl ) {
    48                         return ! LinkageSpec::isBuiltin( decl->get_linkage() );
     55                filter( translationUnit.begin(), translationUnit.end(), back_inserter( decls ), [linkageFilter]( Declaration * decl ) {
     56                        return ! (decl->linkage & linkageFilter);
    4957                });
    5058
  • src/Common/ErrorObjects.h

    r2efe4b8 r1cdfa82  
    3535class SemanticErrorException : public std::exception {
    3636  public:
    37         SemanticErrorException() = default;
     37        SemanticErrorException() = default;
    3838        SemanticErrorException( CodeLocation location, std::string error );
    3939        ~SemanticErrorException() throw() {}
  • src/Common/PassVisitor.h

    r2efe4b8 r1cdfa82  
    6666        virtual void visit( TypedefDecl * typeDecl ) override final;
    6767        virtual void visit( AsmDecl * asmDecl ) override final;
     68        virtual void visit( StaticAssertDecl * assertDecl ) override final;
    6869
    6970        virtual void visit( CompoundStmt * compoundStmt ) override final;
     
    9192        virtual void visit( NameExpr * nameExpr ) override final;
    9293        virtual void visit( CastExpr * castExpr ) override final;
     94        virtual void visit( KeywordCastExpr * castExpr ) override final;
    9395        virtual void visit( VirtualCastExpr * castExpr ) override final;
    9496        virtual void visit( AddressExpr * addressExpr ) override final;
     
    163165        virtual Declaration * mutate( TypedefDecl * typeDecl ) override final;
    164166        virtual AsmDecl * mutate( AsmDecl * asmDecl ) override final;
     167        virtual StaticAssertDecl * mutate( StaticAssertDecl * assertDecl ) override final;
    165168
    166169        virtual CompoundStmt * mutate( CompoundStmt * compoundStmt ) override final;
     
    187190        virtual Expression * mutate( UntypedExpr * untypedExpr ) override final;
    188191        virtual Expression * mutate( NameExpr * nameExpr ) override final;
    189         virtual Expression * mutate( AddressExpr * castExpr ) override final;
     192        virtual Expression * mutate( AddressExpr * addrExpr ) override final;
    190193        virtual Expression * mutate( LabelAddressExpr * labAddressExpr ) override final;
    191194        virtual Expression * mutate( CastExpr * castExpr ) override final;
     195        virtual Expression * mutate( KeywordCastExpr * castExpr ) override final;
    192196        virtual Expression * mutate( VirtualCastExpr * castExpr ) override final;
    193197        virtual Expression * mutate( UntypedMemberExpr * memberExpr ) override final;
  • src/Common/PassVisitor.impl.h

    r2efe4b8 r1cdfa82  
    685685
    686686//--------------------------------------------------------------------------
     687// StaticAssertDecl
     688template< typename pass_type >
     689void PassVisitor< pass_type >::visit( StaticAssertDecl * node ) {
     690        VISIT_START( node );
     691
     692        maybeAccept_impl( node->condition, *this );
     693        maybeAccept_impl( node->message  , *this );
     694
     695        VISIT_END( node );
     696}
     697
     698template< typename pass_type >
     699StaticAssertDecl * PassVisitor< pass_type >::mutate( StaticAssertDecl * node ) {
     700        MUTATE_START( node );
     701
     702        maybeMutate_impl( node->condition, *this );
     703        maybeMutate_impl( node->message  , *this );
     704
     705        MUTATE_END( StaticAssertDecl, node );
     706}
     707
     708//--------------------------------------------------------------------------
    687709// CompoundStmt
    688710template< typename pass_type >
     
    12381260
    12391261//--------------------------------------------------------------------------
     1262// KeywordCastExpr
     1263template< typename pass_type >
     1264void PassVisitor< pass_type >::visit( KeywordCastExpr * node ) {
     1265        VISIT_START( node );
     1266
     1267        indexerScopedAccept( node->result, *this );
     1268        maybeAccept_impl        ( node->arg   , *this );
     1269
     1270        VISIT_END( node );
     1271}
     1272
     1273template< typename pass_type >
     1274Expression * PassVisitor< pass_type >::mutate( KeywordCastExpr * node ) {
     1275        MUTATE_START( node );
     1276
     1277        indexerScopedMutate( node->env   , *this );
     1278        indexerScopedMutate( node->result, *this );
     1279        maybeMutate_impl   ( node->arg   , *this );
     1280
     1281        MUTATE_END( Expression, node );
     1282}
     1283
     1284//--------------------------------------------------------------------------
    12401285// VirtualCastExpr
    12411286template< typename pass_type >
     
    14911536        indexerScopedAccept( node->result, *this );
    14921537        maybeAccept_impl   ( node->type  , *this );
    1493         maybeAccept_impl   ( node->member, *this );
    14941538
    14951539        VISIT_END( node );
     
    15031547        indexerScopedMutate( node->result, *this );
    15041548        maybeMutate_impl   ( node->type  , *this );
    1505         maybeMutate_impl   ( node->member, *this );
    15061549
    15071550        MUTATE_END( Expression, node );
  • src/Common/SemanticError.cc

    r2efe4b8 r1cdfa82  
    6868}
    6969
    70 void SemanticWarningImpl( CodeLocation location, Warning, const char * const fmt, ... ) {
    71         va_list args;
    72         va_start(args, fmt);
    73         std::string msg = fmtToString( fmt, args );
    74         va_end(args);
    75         std::cerr << ErrorHelpers::bold() << location << ErrorHelpers::warning_str() << ErrorHelpers::reset_font() << msg << std::endl;
     70void SemanticWarningImpl( CodeLocation location, Warning warning, const char * const fmt, ... ) {
     71        Severity severity = WarningFormats[(int)warning].severity;
     72        switch(severity) {
     73        case Severity::Suppress :
     74                break;
     75        case Severity::Warn :
     76                {
     77                        va_list args;
     78                        va_start(args, fmt);
     79                        std::string msg = fmtToString( fmt, args );
     80                        va_end(args);
     81                        std::cerr << ErrorHelpers::bold() << location << ErrorHelpers::warning_str() << ErrorHelpers::reset_font() << msg << std::endl;
     82                }
     83                break;
     84        case Severity::Error :
     85                {
     86                        va_list args;
     87                        va_start(args, fmt);
     88                        std::string msg = fmtToString( fmt, args );
     89                        va_end(args);
     90                        SemanticError(location, msg);
     91                }
     92                break;
     93        case Severity::Critical :
     94                assertf(false, "Critical errors not implemented yet");
     95                break;
     96        }
    7697}
    7798
  • src/Common/SemanticError.h

    r2efe4b8 r1cdfa82  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Aug 29 22:03:36 2017
    13 // Update Count     : 17
     12// Last Modified On : Thu Apr 19 17:52:03 2018
     13// Update Count     : 19
    1414//
    1515
     
    3636// Warnings
    3737
    38 constexpr const char * const WarningFormats[] = {
    39         "self assignment of expression: %s",
     38enum class Severity {
     39        Suppress,
     40        Warn,
     41        Error,
     42        Critical
     43};
     44
     45struct WarningData {
     46        const char * const name;
     47        const char * const message;
     48        mutable Severity severity;
     49};
     50
     51constexpr const WarningData WarningFormats[] = {
     52        {"self-assign"         , "self assignment of expression: %s"           , Severity::Warn},
     53        {"reference-conversion", "rvalue to reference conversion of rvalue: %s", Severity::Warn},
     54        {"qualifiers-zero_t-one_t", "questionable use of type qualifier %s with %s", Severity::Warn},
    4055};
    4156
    4257enum class Warning {
    4358        SelfAssignment,
     59        RvalueToReferenceConversion,
     60        BadQualifiersZeroOne,
    4461        NUMBER_OF_WARNINGS, //This MUST be the last warning
    4562};
     
    5067);
    5168
    52 #define SemanticWarning(loc, id, ...) SemanticWarningImpl(loc, id, WarningFormats[(int)id], __VA_ARGS__)
     69#define SemanticWarning(loc, id, ...) SemanticWarningImpl(loc, id, WarningFormats[(int)id].message, __VA_ARGS__)
    5370
    5471void SemanticWarningImpl (CodeLocation loc, Warning warn, const char * const fmt, ...) __attribute__((format(printf, 3, 4)));
  • src/Common/utility.h

    r2efe4b8 r1cdfa82  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Thr Aug 17 11:38:00 2017
    13 // Update Count     : 34
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Apr 20 22:35:33 2018
     13// Update Count     : 38
    1414//
    1515
     
    433433}
    434434
     435// -----------------------------------------------------------------------------
     436// O(1) polymorphic integer ilog2, using clz, which returns the number of leading 0-bits, starting at the most
     437// significant bit (single instruction on x86)
     438
     439template<typename T>
     440inline constexpr T ilog2(const T & t) {
     441        if ( std::is_integral<T>::value ) {
     442                const constexpr int r = sizeof(t) * __CHAR_BIT__ - 1;
     443                if ( sizeof(T) == sizeof(unsigned int ) ) return r - __builtin_clz( t );
     444                if ( sizeof(T) == sizeof(unsigned long) ) return r - __builtin_clzl( t );
     445                if ( sizeof(T) == sizeof(unsigned long long) ) return r - __builtin_clzll( t );
     446        } // if
     447        return -1;
     448} // ilong2
    435449
    436450
Note: See TracChangeset for help on using the changeset viewer.