source: src/Validate/CompoundLiteral.cpp @ ca4f2b2

Last change on this file since ca4f2b2 was c92bdcc, checked in by Andrew Beach <ajbeach@…>, 6 months ago

Updated the rest of the names in src/ (except for the generated files).

  • Property mode set to 100644
File size: 1.8 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2018 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// CompoundLiteral.cpp -- Use variables to implement compound literals.
8//
9// Author           : Andrew Beach
10// Created On       : Mon Nov 15 16:33:00 2021
11// Last Modified By : Andrew Beach
12// Last Modified On : Mon Nov 16  9:47:00 2021
13// Update Count     : 0
14//
15
16#include "CompoundLiteral.hpp"
17
18#include "AST/Decl.hpp"
19#include "AST/Expr.hpp"
20#include "AST/Pass.hpp"
21#include "AST/TranslationUnit.hpp"
22#include "Common/UniqueName.hpp"
23
24namespace Validate {
25
26namespace {
27
28struct CompoundLiteral final :
29                public ast::WithDeclsToAdd<> {
30        ast::Storage::Classes storageClasses;
31
32        void previsit( const ast::ObjectDecl * decl );
33        const ast::Expr * postvisit( const ast::CompoundLiteralExpr * expr );
34};
35
36void CompoundLiteral::previsit( const ast::ObjectDecl * decl ) {
37        storageClasses = decl->storage;
38}
39
40const ast::Expr * CompoundLiteral::postvisit(
41                const ast::CompoundLiteralExpr * expr ) {
42        static UniqueName litName( "_compLit" );
43
44        // Transform: [storageClasses] ... (struct S){...} ...
45        // Into:      [storageClasses] struct S _compLit = {...};
46        //                             ... _compLit ...
47        ast::ObjectDecl * temp = new ast::ObjectDecl(
48                expr->location,
49                litName.newName(),
50                expr->result,
51                expr->init,
52                storageClasses
53                );
54        declsToAddBefore.push_back( temp );
55        return new ast::VariableExpr( expr->location, temp );
56}
57
58} // namespace
59
60void handleCompoundLiterals( ast::TranslationUnit & translationUnit ) {
61        ast::Pass<CompoundLiteral>::run( translationUnit );
62}
63
64} // namespace Validate
65
66// Local Variables: //
67// tab-width: 4 //
68// mode: c++ //
69// compile-command: "make install" //
70// End: //
Note: See TracBrowser for help on using the repository browser.