source: src/AST/Label.hpp @ e0115286

ADTarm-ehast-experimentalcleanup-dtorsenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since e0115286 was e0115286, checked in by Thierry Delisle <tdelisle@…>, 5 years ago

Fix a cyclic dependency with ptr and nodes

  • 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// Label.hpp --
8//
9// Author           : Aaron B. Moss
10// Created On       : Wed May 8 13:00:00 2019
11// Last Modified By : Aaron B. Moss
12// Last Modified On : Wed May 8 13:00:00 2019
13// Update Count     : 1
14//
15
16#pragma once
17
18#include <iostream>
19#include <string>
20#include <vector>
21
22#include "Node.hpp"
23#include "Common/CodeLocation.h"
24
25namespace ast {
26
27class Attribute;
28
29/// Named labels for statements
30class Label {
31public:
32        CodeLocation location;
33        std::string name;
34        std::vector< ptr<Attribute> > attributes;
35
36        Label( CodeLocation loc, const std::string& name = "",
37                const std::vector<ptr<Attribute>>& attrs = std::vector<ptr<Attribute>>{} )
38        : location( loc ), name( name ), attributes( attrs ) {}
39
40        operator std::string () const { return name; }
41        bool empty() { return name.empty(); }
42};
43
44inline bool operator== ( const Label& l1, const Label& l2 ) { return l1.name == l2.name; }
45inline bool operator!= ( const Label& l1, const Label& l2 ) { return !(l1 == l2); }
46inline bool operator<  ( const Label& l1, const Label& l2 ) { return l1.name < l2.name; }
47
48inline std::ostream& operator<< ( std::ostream& out, const Label& l ) { return out << l.name; }
49
50
51//=================================================================================================
52/// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency
53/// remove only if there is a better solution
54/// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with
55/// forward declarations
56inline void increment( const class Label * node, Node::ref_type ref ) { node->increment( ref ); }
57inline void decrement( const class Label * node, Node::ref_type ref ) { node->decrement( ref ); }
58
59}
60
61// Local Variables: //
62// tab-width: 4 //
63// mode: c++ //
64// compile-command: "make install" //
65// End: //
Note: See TracBrowser for help on using the repository browser.