source: src/ControlStruct/LabelGenerator.cc@ 00a8e19

ADT ast-experimental enum forall-pointer-decay pthread-emulation qualifiedEnum
Last change on this file since 00a8e19 was de31a1d, checked in by Andrew Beach <ajbeach@…>, 4 years ago

Converted the two LabelGenerator singletons into a single pure-static class.

  • Property mode set to 100644
File size: 2.0 KB
Line 
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// LabelGenerator.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 : Mon Nov 8 10:18:00 2021
13// Update Count : 17
14//
15
16#include <iostream> // for operator<<, basic_ostream
17#include <sstream> // for ostringstream
18#include <list> // for list
19
20#include "LabelGenerator.h"
21
22#include "AST/Attribute.hpp"
23#include "AST/Label.hpp"
24#include "AST/Stmt.hpp"
25#include "SynTree/Attribute.h" // for Attribute
26#include "SynTree/Label.h" // for Label, operator<<
27#include "SynTree/Statement.h" // for Statement
28
29namespace ControlStruct {
30
31int LabelGenerator::current = 0;
32LabelGenerator * LabelGenerator::labelGenerator = nullptr;
33
34 LabelGenerator * LabelGenerator::getGenerator() {
35 if ( LabelGenerator::labelGenerator == 0 )
36 LabelGenerator::labelGenerator = new LabelGenerator();
37 return labelGenerator;
38 }
39
40 Label LabelGenerator::newLabel( std::string suffix, Statement * stmt ) {
41 std::ostringstream os;
42 os << "__L" << current++ << "__" << suffix;
43 if ( stmt && ! stmt->get_labels().empty() ) {
44 os << "_" << stmt->get_labels().front() << "__";
45 } // if
46 std::string ret = os.str();
47 Label l( ret );
48 l.get_attributes().push_back( new Attribute("unused") );
49 return l;
50 }
51
52ast::Label LabelGenerator::newLabel(
53 const std::string & suffix, const ast::Stmt * stmt ) {
54 assert( stmt );
55
56 std::ostringstream os;
57 os << "__L" << current++ << "__" << suffix;
58 if ( stmt && !stmt->labels.empty() ) {
59 os << "_" << stmt->labels.front() << "__";
60 }
61 ast::Label ret_label( stmt->location, os.str() );
62 ret_label.attributes.push_back( new ast::Attribute( "unused" ) );
63 return ret_label;
64}
65
66} // namespace ControlStruct
67
68// Local Variables: //
69// tab-width: 4 //
70// mode: c++ //
71// compile-command: "make install" //
72// End: //
Note: See TracBrowser for help on using the repository browser.