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 |
---|
11 | // Last Modified By : Andrew Beach |
---|
12 | // Last Modified On : Tue May 17 15:02:00 2022 |
---|
13 | // Update Count : 25 |
---|
14 | // |
---|
15 | |
---|
16 | #include <stddef.h> // for size_t |
---|
17 | #include <cassert> // for assert |
---|
18 | #include <list> // for list |
---|
19 | #include <vector> |
---|
20 | |
---|
21 | #include "AST/CVQualifiers.hpp" |
---|
22 | #include "AST/Expr.hpp" |
---|
23 | #include "AST/Node.hpp" |
---|
24 | #include "AST/Type.hpp" |
---|
25 | #include "Common/ScopedMap.h" // for ScopedMap |
---|
26 | #include "Common/utility.h" // for CodeLocation |
---|
27 | #include "InitTweak/InitTweak.h" // for getFunction |
---|
28 | #include "Tuples.h" |
---|
29 | |
---|
30 | namespace Tuples { |
---|
31 | |
---|
32 | const ast::Type * makeTupleType( const std::vector<ast::ptr<ast::Expr>> & exprs ) { |
---|
33 | // produce the TupleType which aggregates the types of the exprs |
---|
34 | std::vector<ast::ptr<ast::Type>> types; |
---|
35 | ast::CV::Qualifiers quals{ |
---|
36 | ast::CV::Const | ast::CV::Volatile | ast::CV::Restrict | |
---|
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 }; |
---|
52 | } |
---|
53 | |
---|
54 | const ast::TypeInstType * isTtype( const ast::Type * type ) { |
---|
55 | if ( const ast::TypeInstType * inst = dynamic_cast< const ast::TypeInstType * >( type ) ) { |
---|
56 | if ( inst->base && inst->base->kind == ast::TypeDecl::Ttype ) { |
---|
57 | return inst; |
---|
58 | } |
---|
59 | } |
---|
60 | return nullptr; |
---|
61 | } |
---|
62 | } // namespace Tuples |
---|
63 | |
---|
64 | // Local Variables: // |
---|
65 | // tab-width: 4 // |
---|
66 | // mode: c++ // |
---|
67 | // compile-command: "make install" // |
---|
68 | // End: // |
---|