source: src/Tuples/TupleExpansion.cc @ 8c13ca8

Last change on this file since 8c13ca8 was c6b4432, checked in by Andrew Beach <ajbeach@…>, 12 months ago

Remove BaseSyntaxNode? and clean-up.

  • Property mode set to 100644
File size: 2.1 KB
RevLine 
[6eb8948]1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// TupleAssignment.cc --
8//
9// Author           : Rodolfo G. Esteves
10// Created On       : Mon May 18 07:44:20 2015
[9939dc3]11// Last Modified By : Andrew Beach
12// Last Modified On : Tue May 17 15:02:00 2022
13// Update Count     : 25
[6eb8948]14//
15
[03321e4]16#include <stddef.h>               // for size_t
17#include <cassert>                // for assert
18#include <list>                   // for list
[9b4f329]19#include <vector>
[03321e4]20
[9b4f329]21#include "AST/CVQualifiers.hpp"
22#include "AST/Expr.hpp"
23#include "AST/Node.hpp"
24#include "AST/Type.hpp"
[03321e4]25#include "Common/ScopedMap.h"     // for ScopedMap
26#include "Common/utility.h"       // for CodeLocation
27#include "InitTweak/InitTweak.h"  // for getFunction
[aee472e]28#include "Tuples.h"
[03321e4]29
[6eb8948]30namespace Tuples {
[3c13c03]31
[9b4f329]32        const ast::Type * makeTupleType( const std::vector<ast::ptr<ast::Expr>> & exprs ) {
[3ca912a]33                // produce the TupleType which aggregates the types of the exprs
34                std::vector<ast::ptr<ast::Type>> types;
35                ast::CV::Qualifiers quals{
[3f3bfe5a]36                        ast::CV::Const | ast::CV::Volatile | ast::CV::Restrict |
[3ca912a]37                        ast::CV::Atomic | ast::CV::Mutex };
38
39                for ( const ast::Expr * expr : exprs ) {
40                        assert( expr->result );
41                        // if the type of any expr is void, the type of the entire tuple is void
42                        if ( expr->result->isVoid() ) return new ast::VoidType{};
43
44                        // qualifiers on the tuple type are the qualifiers that exist on all components
45                        quals &= expr->result->qualifiers;
46
47                        types.emplace_back( expr->result );
48                }
49
50                if ( exprs.empty() ) { quals = ast::CV::Qualifiers{}; }
51                return new ast::TupleType{ std::move(types), quals };
[9b4f329]52        }
[65660bd]53
[0588d8c]54        const ast::TypeInstType * isTtype( const ast::Type * type ) {
[3ca912a]55                if ( const ast::TypeInstType * inst = dynamic_cast< const ast::TypeInstType * >( type ) ) {
[07de76b]56                        if ( inst->base && inst->base->kind == ast::TypeDecl::Ttype ) {
[3ca912a]57                                return inst;
58                        }
59                }
[0588d8c]60                return nullptr;
61        }
[6eb8948]62} // namespace Tuples
63
64// Local Variables: //
65// tab-width: 4 //
66// mode: c++ //
67// compile-command: "make install" //
68// End: //
Note: See TracBrowser for help on using the repository browser.