source: src/Validate/CompoundLiteral.cpp @ 2cf3b87

ADTast-experimentalenumforall-pointer-decaypthread-emulationqualifiedEnum
Last change on this file since 2cf3b87 was 2cf3b87, checked in by Andrew Beach <ajbeach@…>, 2 years ago

Translated valitate-E after much bug hunting.

  • Property mode set to 100644
File size: 1.8 KB
RevLine 
[2cf3b87]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.h"
23
24namespace Validate {
25
26namespace {
27
28struct CompoundLiteral final :
29                public ast::WithDeclsToAdd<>,
30                public ast::WithVisitorRef<CompoundLiteral> {
31        ast::Storage::Classes storageClasses;
32
33        void previsit( const ast::ObjectDecl * decl );
34        const ast::Expr * postvisit( const ast::CompoundLiteralExpr * expr );
35};
36
37void CompoundLiteral::previsit( const ast::ObjectDecl * decl ) {
38        storageClasses = decl->storage;
39}
40
41const ast::Expr * CompoundLiteral::postvisit(
42                const ast::CompoundLiteralExpr * expr ) {
43        static UniqueName litName( "_compLit" );
44
45        // Transform: [storageClasses] ... (struct S){...} ...
46        // Into:      [storageClasses] struct S _compLit = {...}; / ... temp ...
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.