source: src/SynTree/Label.h@ 4d3ca1d8

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors ctor deferred_resn demangler enum forall-pointer-decay gc_noraii jacob/cs343-translation jenkins-sandbox memory new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since 4d3ca1d8 was 23b6f4d7, checked in by Rob Schluntz <rschlunt@…>, 9 years ago

change Label type from std::string to a custom Label class, link label to its statement

  • Property mode set to 100644
File size: 2.1 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// Label.h --
8//
9// Author : Rob Schluntz
10// Created On : Wed Jun 8 12:53:12 2016
11// Last Modified By : Rob Schluntz
12// Last Modified On : Wed Jun 8 12:53:28 2016
13// Update Count : 1
14//
15
16#ifndef LABEL_H
17#define LABEL_H
18
19#include <string>
20#include <list>
21#include <iostream>
22#include "SynTree.h"
23
24// Label needs to know
25// * how deeply nested it is (scopeLevel)
26// * relative position in a scope compared with other labels (index?)
27// * either the original label it was generated from or the labels it generates (for labelled break/continue)
28
29class Label {
30 public:
31 Label( const std::string & name = "", Statement * labelled = 0 ) : name( name ), labelled( labelled ) {}
32 Label( const char * name, Statement * labelled = 0 ) : name( name ), labelled( labelled ) {}
33
34 const std::string & get_name() const { return name; }
35 void set_name( const std::string & newValue ) { name = newValue; }
36
37 Statement * get_statement() const { return labelled; }
38 void set_statement( Statement * newValue ) { labelled = newValue; }
39 std::list< Attribute * >& get_attributes() { return attributes; }
40
41 operator std::string() { return name; }
42 bool empty() { return name.empty(); }
43 private:
44 std::string name;
45 Statement * labelled;
46 std::list< Attribute * > attributes;
47};
48
49inline bool operator==( Label l1, Label l2 ) { return l1.get_name() == l2.get_name(); }
50inline bool operator!=( Label l1, Label l2 ) { return ! (l1 == l2); }
51inline bool operator<( Label l1, Label l2 ) { return l1.get_name() < l2.get_name(); }
52// inline Label operator+( Label l1, Label l2 ) { return l1.get_name() + l2.get_name(); }
53// inline Label operator+( Label l1, const char * str ) { return l1.get_name() + Label( str ); }
54inline std::ostream & operator<<( std::ostream & out, const Label & l ) { return out << l.get_name(); }
55
56static const std::list< Label > noLabels;
57
58#endif // LABEL_H
59
60// Local Variables: //
61// tab-width: 4 //
62// mode: c++ //
63// compile-command: "make install" //
64// End: //
Note: See TracBrowser for help on using the repository browser.