Changeset 1931bb0


Ignore:
Timestamp:
Jul 12, 2022, 3:21:18 PM (5 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
master, pthread-emulation, qualifiedEnum
Children:
b9f8274
Parents:
9c6443e
Message:

Converted 'Validate A' to the new AST. There some utility changes as well.

Location:
src
Files:
10 added
10 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r9c6443e r1931bb0  
    168168                auto attr = get<Attribute>().acceptL( node->attributes );
    169169
     170                // This field can be unset very early on (Pre-FixReturnTypes).
     171                auto newType = (type) ? type->clone() : nullptr;
     172
    170173                auto decl = new ObjectDecl(
    171174                        node->name,
     
    173176                        LinkageSpec::Spec( node->linkage.val ),
    174177                        bfwd,
    175                         type->clone(),
     178                        newType,
    176179                        nullptr, // prevent infinite loop
    177180                        attr,
     
    15791582
    15801583        virtual void visit( const ObjectDecl * old ) override final {
     1584                if ( inCache( old ) ) {
     1585                        return;
     1586                }
    15811587                auto&& type = GET_ACCEPT_1(type, Type);
    15821588                auto&& init = GET_ACCEPT_1(init, Init);
    15831589                auto&& bfwd = GET_ACCEPT_1(bitfieldWidth, Expr);
    15841590                auto&& attr = GET_ACCEPT_V(attributes, Attribute);
    1585                 if ( inCache( old ) ) {
    1586                         return;
    1587                 }
     1591
    15881592                auto decl = new ast::ObjectDecl(
    15891593                        old->location,
  • src/AST/Decl.hpp

    r9c6443e r1931bb0  
    315315
    316316        EnumDecl( const CodeLocation& loc, const std::string& name,
    317                 std::vector<ptr<Attribute>>&& attrs = {}, Linkage::Spec linkage = Linkage::Cforall, Type * base = nullptr,
     317                std::vector<ptr<Attribute>>&& attrs = {}, Linkage::Spec linkage = Linkage::Cforall, Type const * base = nullptr,
    318318                std::unordered_map< std::string, long long > enumValues = std::unordered_map< std::string, long long >() )
    319319        : AggregateDecl( loc, name, std::move(attrs), linkage ), base(base), enumValues(enumValues) {}
  • src/CodeGen/CodeGenerator.cc

    r9c6443e r1931bb0  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb  2 20:30:30 2022
    13 // Update Count     : 541
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed Jun 29 14:34:00 2022
     13// Update Count     : 542
    1414//
    1515#include "CodeGenerator.h"
     
    1818#include <list>                      // for _List_iterator, list, list<>::it...
    1919
     20#include "AST/Decl.hpp"              // for DeclWithType
    2021#include "Common/UniqueName.h"       // for UniqueName
    2122#include "Common/utility.h"          // for CodeLocation, toString
     
    12381239                } // if
    12391240        }
     1241
     1242std::string genName( ast::DeclWithType const * decl ) {
     1243        if ( const OperatorInfo * opInfo = operatorLookup( decl->name ) ) {
     1244                return opInfo->outputName;
     1245        } else {
     1246                return decl->name;
     1247        }
     1248}
     1249
    12401250} // namespace CodeGen
    12411251
  • src/CodeGen/CodeGenerator.h

    r9c6443e r1931bb0  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Feb  1 09:23:21 2022
    13 // Update Count     : 64
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed Jun 29 14:32:00 2022
     13// Update Count     : 65
    1414//
    1515
     
    2626#include "SynTree/Visitor.h"      // for Visitor
    2727#include "SynTree/SynTree.h"      // for Visitor Nodes
     28
     29namespace ast {
     30        class DeclWithType;
     31}
    2832
    2933namespace CodeGen {
     
    182186        /// returns C-compatible name of declaration
    183187        std::string genName( DeclarationWithType * decl );
     188        std::string genName( ast::DeclWithType const * decl );
    184189
    185190        inline std::ostream & operator<<( std::ostream & os, const CodeGenerator::LineEnder & endl ) {
  • src/CodeGen/GenType.cc

    r9c6443e r1931bb0  
    254254
    255255        void GenType::postvisit( EnumInstType * enumInst ) {
    256                 if ( enumInst->baseEnum->base ) {
     256                if ( enumInst->baseEnum && enumInst->baseEnum->base ) {
    257257                        typeString = genType(enumInst->baseEnum->base, "", options) + typeString;
    258258                } else {
  • src/SymTab/FixFunction.cc

    r9c6443e r1931bb0  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 16:19:49 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Mar  6 23:36:59 2017
    13 // Update Count     : 6
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Tue Jul 12 14:28:00 2022
     13// Update Count     : 7
    1414//
    1515
     
    122122                }
    123123
     124                void previsit( const ast::FunctionType * ) { visit_children = false; }
     125
     126                const ast::Type * postvisit( const ast::FunctionType * type ) {
     127                        return new ast::PointerType( type );
     128                }
     129
    124130                void previsit( const ast::VoidType * ) { isVoid = true; }
    125131
     
    145151}
    146152
     153const ast::Type * fixFunction( const ast::Type * type, bool & isVoid ) {
     154        ast::Pass< FixFunction_new > fixer;
     155        type = type->accept( fixer );
     156        isVoid |= fixer.core.isVoid;
     157        return type;
     158}
     159
    147160} // namespace SymTab
    148161
  • src/SymTab/FixFunction.h

    r9c6443e r1931bb0  
    1010// Created On       : Sun May 17 17:02:08 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:45:55 2017
    13 // Update Count     : 4
     12// Last Modified On : Tue Jul 12 14:19:00 2022
     13// Update Count     : 5
    1414//
    1515
     
    2121namespace ast {
    2222        class DeclWithType;
     23        class Type;
    2324}
    2425
     
    3132        /// Sets isVoid to true if type is void
    3233        const ast::DeclWithType * fixFunction( const ast::DeclWithType * dwt, bool & isVoid );
     34        const ast::Type * fixFunction( const ast::Type * type, bool & isVoid );
    3335} // namespace SymTab
    3436
  • src/Validate/EliminateTypedef.cpp

    r9c6443e r1931bb0  
    1010// Created On       : Wed Apr 20 16:37:00 2022
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Mon Apr 25 14:26:00 2022
    13 // Update Count     : 0
     12// Last Modified On : Mon Jul 11 16:30:00 2022
     13// Update Count     : 1
    1414//
    1515
     
    2828
    2929struct EliminateTypedefCore {
     30        // Remove typedefs from inside aggregates.
    3031        ast::StructDecl const * previsit( ast::StructDecl const * decl );
    3132        ast::UnionDecl const * previsit( ast::UnionDecl const * decl );
     33        // Remove typedefs from statement lists.
    3234        ast::CompoundStmt const * previsit( ast::CompoundStmt const * stmt );
     35        // Remove typedefs from control structure initializers.
     36        ast::IfStmt const * previsit( ast::IfStmt const * stmt );
     37        ast::ForStmt const * previsit( ast::ForStmt const * stmt );
     38        ast::WhileDoStmt const * previsit( ast::WhileDoStmt const * stmt );
    3339};
    3440
     
    6369}
    6470
     71ast::IfStmt const * EliminateTypedefCore::previsit( ast::IfStmt const * stmt ) {
     72        return field_erase_if( stmt, &ast::IfStmt::inits, isTypedefStmt );
     73}
     74
     75ast::ForStmt const * EliminateTypedefCore::previsit( ast::ForStmt const * stmt ) {
     76        return field_erase_if( stmt, &ast::ForStmt::inits, isTypedefStmt );
     77}
     78
     79ast::WhileDoStmt const * EliminateTypedefCore::previsit( ast::WhileDoStmt const * stmt ) {
     80        return field_erase_if( stmt, &ast::WhileDoStmt::inits, isTypedefStmt );
     81}
     82
    6583} // namespace
    6684
  • src/Validate/module.mk

    r9c6443e r1931bb0  
    2626        Validate/EliminateTypedef.cpp \
    2727        Validate/EliminateTypedef.hpp \
     28        Validate/EnumAndPointerDecay.cpp \
     29        Validate/EnumAndPointerDecay.hpp \
    2830        Validate/FindSpecialDeclsNew.cpp \
    2931        Validate/FixQualifiedTypes.cpp \
    3032        Validate/FixQualifiedTypes.hpp \
     33        Validate/FixReturnTypes.cpp \
     34        Validate/FixReturnTypes.hpp \
    3135        Validate/ForallPointerDecay.cpp \
    3236        Validate/ForallPointerDecay.hpp \
     
    3741        Validate/HoistStruct.cpp \
    3842        Validate/HoistStruct.hpp \
     43        Validate/HoistTypeDecls.cpp \
     44        Validate/HoistTypeDecls.hpp \
    3945        Validate/InitializerLength.cpp \
    4046        Validate/InitializerLength.hpp \
     
    4450        Validate/LinkReferenceToTypes.hpp \
    4551        Validate/NoIdSymbolTable.hpp \
     52        Validate/ReplaceTypedef.cpp \
     53        Validate/ReplaceTypedef.hpp \
    4654        Validate/ReturnCheck.cpp \
    47         Validate/ReturnCheck.hpp
     55        Validate/ReturnCheck.hpp \
     56        Validate/VerifyCtorDtorAssign.cpp \
     57        Validate/VerifyCtorDtorAssign.hpp
    4858
    4959SRCDEMANGLE += $(SRC_VALIDATE)
  • src/main.cc

    r9c6443e r1931bb0  
    1010// Created On       : Fri May 15 23:12:02 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Tue Jun  7 13:29:00 2022
    13 // Update Count     : 674
     12// Last Modified On : Tue Jul 12 12:02:00 2022
     13// Update Count     : 675
    1414//
    1515
     
    7878#include "Validate/CompoundLiteral.hpp"     // for handleCompoundLiterals
    7979#include "Validate/EliminateTypedef.hpp"    // for eliminateTypedef
     80#include "Validate/EnumAndPointerDecay.hpp" // for decayEnumsAndPointers
    8081#include "Validate/FindSpecialDecls.h"      // for findGlobalDecls
    8182#include "Validate/FixQualifiedTypes.hpp"   // for fixQualifiedTypes
     83#include "Validate/FixReturnTypes.hpp"      // for fixReturnTypes
    8284#include "Validate/ForallPointerDecay.hpp"  // for decayForallPointers
    8385#include "Validate/GenericParameter.hpp"    // for fillGenericParameters, tr...
    8486#include "Validate/HoistStruct.hpp"         // for hoistStruct
     87#include "Validate/HoistTypeDecls.hpp"      // for hoistTypeDecls
    8588#include "Validate/InitializerLength.hpp"   // for setLengthFromInitializer
    8689#include "Validate/LabelAddressFixer.hpp"   // for fixLabelAddresses
    8790#include "Validate/LinkReferenceToTypes.hpp" // for linkReferenceToTypes
     91#include "Validate/ReplaceTypedef.hpp"      // for replaceTypedef
    8892#include "Validate/ReturnCheck.hpp"         // for checkReturnStatements
     93#include "Validate/VerifyCtorDtorAssign.hpp" // for verifyCtorDtorAssign
    8994#include "Virtual/ExpandCasts.h"            // for expandCasts
    9095
     
    331336                } // if
    332337
    333                 // add the assignment statement after the initialization of a type parameter
    334                 PASS( "Validate-A", SymTab::validate_A( translationUnit ) );
    335 
    336338                CodeTools::fillLocations( translationUnit );
    337339
     
    346348
    347349                        forceFillCodeLocations( transUnit );
     350
     351                        // Must happen before auto-gen, or anything that examines ops.
     352                        PASS( "Verify Ctor, Dtor & Assign", Validate::verifyCtorDtorAssign( transUnit ) );
     353
     354                        PASS( "Hoist Type Decls", Validate::hoistTypeDecls( transUnit ) );
     355                        // Hoist Type Decls pulls some declarations out of contexts where
     356                        // locations are not tracked. Perhaps they should be, but for now
     357                        // the full fill solves it.
     358                        forceFillCodeLocations( transUnit );
     359
     360                        PASS( "Replace Typedefs", Validate::replaceTypedef( transUnit ) );
     361
     362                        // Must happen before auto-gen.
     363                        PASS( "Fix Return Types", Validate::fixReturnTypes( transUnit ) );
     364
     365                        // Must happen before Link Reference to Types, it needs correct
     366                        // types for mangling.
     367                        PASS( "Enum and Pointer Decay", Validate::decayEnumsAndPointers( transUnit ) );
    348368
    349369                        // Must happen before auto-gen, because it uses the sized flag.
     
    453473                        translationUnit = convert( move( transUnit ) );
    454474                } else {
     475                        // add the assignment statement after the initialization of a type parameter
     476                        PASS( "Validate-A", SymTab::validate_A( translationUnit ) );
    455477                        PASS( "Validate-B", SymTab::validate_B( translationUnit ) );
    456478                        PASS( "Validate-C", SymTab::validate_C( translationUnit ) );
Note: See TracChangeset for help on using the changeset viewer.