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 |
|
---|
29 | namespace ControlStruct {
|
---|
30 |
|
---|
31 | int LabelGenerator::current = 0;
|
---|
32 | LabelGenerator * 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 |
|
---|
52 | ast::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: //
|
---|