Changeset 9490621


Ignore:
Timestamp:
Feb 11, 2022, 11:00:35 AM (2 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
Children:
51b8582
Parents:
5910fc0
Message:

My work in progress implementation of ForallPointerDecay? for Fangren.

Location:
src
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Decl.cpp

    r5910fc0 r9490621  
    3939        if ( uniqueId ) return;  // ensure only set once
    4040        uniqueId = ++lastUniqueId;
    41         idMap[ uniqueId ] = this;
     41        //idMap[ uniqueId ] = this;
    4242}
    4343
    4444readonly<Decl> Decl::fromId( UniqueId id ) {
     45        assert( false );
    4546        IdMapType::const_iterator i = idMap.find( id );
    4647        if ( i != idMap.end() ) return i->second;
  • src/SymTab/Validate.cc

    r5910fc0 r9490621  
    194194        };
    195195
     196        // These structs are the sub-sub-passes of ForallPointerDecay_old.
     197
     198        struct TraitExpander_old final {
     199                void previsit( FunctionType * );
     200                void previsit( StructDecl * );
     201                void previsit( UnionDecl * );
     202        };
     203
     204        struct AssertionFixer_old final {
     205                void previsit( FunctionType * );
     206                void previsit( StructDecl * );
     207                void previsit( UnionDecl * );
     208        };
     209
     210        struct CheckOperatorTypes_old final {
     211                void previsit( ObjectDecl * );
     212        };
     213
     214        struct FixUniqueIds_old final {
     215                void previsit( DeclarationWithType * );
     216        };
     217
    196218        struct ReturnChecker : public WithGuards {
    197219                /// Checks that return statements return nothing if their return type is void
     
    386408
    387409        void validate_D( std::list< Declaration * > & translationUnit ) {
    388                 PassVisitor<ForallPointerDecay_old> fpd;
    389410                {
    390411                        Stats::Heap::newPass("validate-D");
     
    394415                        });
    395416                        Stats::Time::TimeBlock("Forall Pointer Decay", [&]() {
    396                                 acceptAll( translationUnit, fpd ); // must happen before autogenerateRoutines, after Concurrency::applyKeywords because uniqueIds must be set on declaration before resolution
     417                                decayForallPointers( translationUnit ); // must happen before autogenerateRoutines, after Concurrency::applyKeywords because uniqueIds must be set on declaration before resolution
    397418                        });
    398419                        Stats::Time::TimeBlock("Hoist Control Declarations", [&]() {
     
    454475
    455476        void decayForallPointers( std::list< Declaration * > & translationUnit ) {
    456                 PassVisitor<ForallPointerDecay_old> fpd;
    457                 acceptAll( translationUnit, fpd );
     477                PassVisitor<TraitExpander_old> te;
     478                acceptAll( translationUnit, te );
     479                PassVisitor<AssertionFixer_old> af;
     480                acceptAll( translationUnit, af );
     481                PassVisitor<CheckOperatorTypes_old> cot;
     482                acceptAll( translationUnit, cot );
     483                PassVisitor<FixUniqueIds_old> fui;
     484                acceptAll( translationUnit, fui );
     485        }
     486
     487        void decayForallPointersA( std::list< Declaration * > & translationUnit ) {
     488                PassVisitor<TraitExpander_old> te;
     489                acceptAll( translationUnit, te );
     490        }
     491        void decayForallPointersB( std::list< Declaration * > & translationUnit ) {
     492                PassVisitor<AssertionFixer_old> af;
     493                acceptAll( translationUnit, af );
     494        }
     495        void decayForallPointersC( std::list< Declaration * > & translationUnit ) {
     496                PassVisitor<CheckOperatorTypes_old> cot;
     497                acceptAll( translationUnit, cot );
     498        }
     499        void decayForallPointersD( std::list< Declaration * > & translationUnit ) {
     500                PassVisitor<FixUniqueIds_old> fui;
     501                acceptAll( translationUnit, fui );
    458502        }
    459503
     
    470514                PassVisitor<EnumAndPointerDecay_old> epc;
    471515                PassVisitor<LinkReferenceToTypes_old> lrt( indexer );
    472                 PassVisitor<ForallPointerDecay_old> fpd;
     516                PassVisitor<TraitExpander_old> te;
     517                PassVisitor<AssertionFixer_old> af;
     518                PassVisitor<CheckOperatorTypes_old> cot;
     519                PassVisitor<FixUniqueIds_old> fui;
    473520                type->accept( epc );
    474521                type->accept( lrt );
    475                 type->accept( fpd );
     522                type->accept( te );
     523                type->accept( af );
     524                type->accept( cot );
     525                type->accept( fui );
    476526        }
    477527
     
    9721022        }
    9731023
     1024        /// Replace all traits in assertion lists with their assertions.
     1025        void expandTraits( std::list< TypeDecl * > & forall ) {
     1026                for ( TypeDecl * type : forall ) {
     1027                        std::list< DeclarationWithType * > asserts;
     1028                        asserts.splice( asserts.end(), type->assertions );
     1029                        // expand trait instances into their members
     1030                        for ( DeclarationWithType * assertion : asserts ) {
     1031                                if ( TraitInstType * traitInst = dynamic_cast< TraitInstType * >( assertion->get_type() ) ) {
     1032                                        // expand trait instance into all of its members
     1033                                        expandAssertions( traitInst, back_inserter( type->assertions ) );
     1034                                        delete traitInst;
     1035                                } else {
     1036                                        // pass other assertions through
     1037                                        type->assertions.push_back( assertion );
     1038                                } // if
     1039                        } // for
     1040                }
     1041        }
     1042
     1043        /// Fix each function in the assertion list and check for invalid void type.
     1044        void fixAssertions(
     1045                        std::list< TypeDecl * > & forall, BaseSyntaxNode * node ) {
     1046                for ( TypeDecl * type : forall ) {
     1047                        for ( DeclarationWithType *& assertion : type->assertions ) {
     1048                                bool isVoid = fixFunction( assertion );
     1049                                if ( isVoid ) {
     1050                                        SemanticError( node, "invalid type void in assertion of function " );
     1051                                } // if
     1052                        } // for
     1053                }
     1054        }
     1055
    9741056        void ForallPointerDecay_old::previsit( ObjectDecl * object ) {
    9751057                // ensure that operator names only apply to functions or function pointers
     
    9941076        void ForallPointerDecay_old::previsit( UnionDecl * aggrDecl ) {
    9951077                forallFixer( aggrDecl->parameters, aggrDecl );
     1078        }
     1079
     1080        void TraitExpander_old::previsit( FunctionType * ftype ) {
     1081                expandTraits( ftype->forall );
     1082        }
     1083
     1084        void TraitExpander_old::previsit( StructDecl * aggrDecl ) {
     1085                expandTraits( aggrDecl->parameters );
     1086        }
     1087
     1088        void TraitExpander_old::previsit( UnionDecl * aggrDecl ) {
     1089                expandTraits( aggrDecl->parameters );
     1090        }
     1091
     1092        void AssertionFixer_old::previsit( FunctionType * ftype ) {
     1093                fixAssertions( ftype->forall, ftype );
     1094        }
     1095
     1096        void AssertionFixer_old::previsit( StructDecl * aggrDecl ) {
     1097                fixAssertions( aggrDecl->parameters, aggrDecl );
     1098        }
     1099
     1100        void AssertionFixer_old::previsit( UnionDecl * aggrDecl ) {
     1101                fixAssertions( aggrDecl->parameters, aggrDecl );
     1102        }
     1103
     1104        void CheckOperatorTypes_old::previsit( ObjectDecl * object ) {
     1105                // ensure that operator names only apply to functions or function pointers
     1106                if ( CodeGen::isOperator( object->name ) && ! dynamic_cast< FunctionType * >( object->type->stripDeclarator() ) ) {
     1107                        SemanticError( object->location, toCString( "operator ", object->name.c_str(), " is not a function or function pointer." )  );
     1108                }
     1109        }
     1110
     1111        void FixUniqueIds_old::previsit( DeclarationWithType * decl ) {
     1112                decl->fixUniqueId();
    9961113        }
    9971114
  • src/SymTab/Validate.h

    r5910fc0 r9490621  
    4343        void validate_F( std::list< Declaration * > &translationUnit );
    4444        void decayForallPointers( std::list< Declaration * > & translationUnit );
     45        void decayForallPointersA( std::list< Declaration * > & translationUnit );
     46        void decayForallPointersB( std::list< Declaration * > & translationUnit );
     47        void decayForallPointersC( std::list< Declaration * > & translationUnit );
     48        void decayForallPointersD( std::list< Declaration * > & translationUnit );
    4549
    4650        const ast::Type * validateType(
  • src/Validate/module.mk

    r5910fc0 r9490621  
    2020        Validate/CompoundLiteral.cpp \
    2121        Validate/CompoundLiteral.hpp \
     22        Validate/ForallPointerDecay.cpp \
     23        Validate/ForallPointerDecay.hpp \
    2224        Validate/HandleAttributes.cc \
    2325        Validate/HandleAttributes.h \
  • src/main.cc

    r5910fc0 r9490621  
    3232
    3333#include "AST/Convert.hpp"
     34#include "AST/Print.hpp"
    3435#include "CompilationState.h"
    3536#include "../config.h"                      // for CFA_LIBDIR
     
    7677#include "Validate/Autogen.hpp"             // for autogenerateRoutines
    7778#include "Validate/FindSpecialDecls.h"      // for findGlobalDecls
     79#include "Validate/ForallPointerDecay.hpp"  // for decayForallPointers
    7880#include "Validate/CompoundLiteral.hpp"     // for handleCompoundLiterals
    7981#include "Validate/InitializerLength.hpp"   // for setLengthFromInitializer
     
    331333
    332334                if( useNewAST ) {
    333                         PASS( "Apply Concurrent Keywords", Concurrency::applyKeywords( translationUnit ) );
    334                         PASS( "Forall Pointer Decay", SymTab::decayForallPointers( translationUnit ) );
     335                        PASS( "Implement Concurrent Keywords", Concurrency::applyKeywords( translationUnit ) );
     336                        //PASS( "Forall Pointer Decay - A", SymTab::decayForallPointersA( translationUnit ) );
     337                        //PASS( "Forall Pointer Decay - B", SymTab::decayForallPointersB( translationUnit ) );
     338                        //PASS( "Forall Pointer Decay - C", SymTab::decayForallPointersC( translationUnit ) );
     339                        //PASS( "Forall Pointer Decay - D", SymTab::decayForallPointersD( translationUnit ) );
    335340                        CodeTools::fillLocations( translationUnit );
    336341
     
    342347
    343348                        forceFillCodeLocations( transUnit );
     349
     350                        // Must be after implement concurrent keywords; because uniqueIds
     351                        //   must be set on declaration before resolution.
     352                        // Must happen before autogen routines are added.
     353                        PASS( "Forall Pointer Decay", Validate::decayForallPointers( transUnit ) );
    344354
    345355                        // Must happen before autogen routines are added.
Note: See TracChangeset for help on using the changeset viewer.