//
// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
//
// The contents of this file are covered under the licence agreement in the
// file "LICENCE" distributed with Cforall.
//
// Attribute.hpp --
//
// Author           : Aaron B. Moss
// Created On       : Fri May 10 10:30:00 2019
// Last Modified By : Aaron B. Moss
// Created On       : Fri May 10 10:30:00 2019
// Update Count     : 1
//

#pragma once

#include <string>
#include <vector>

#include "Fwd.hpp"
#include "Node.hpp"     // for ptr
#include "Visitor.hpp"

namespace ast {

class Expr;

class Attribute final : public Node {
public:
	std::string name;
	std::vector<ptr<Expr>> parameters;

	Attribute( const std::string & name = "", std::vector<ptr<Expr>> && params = {})
	: name( name ), parameters( params ) {}
	virtual ~Attribute() = default;

	bool empty() const { return name.empty(); }

	/// strip leading/trailing underscores and lowercase
	std::string normalizedName() const;

	/// true iff this attribute is allowed to appear attached to a function parameter
	bool isValidOnFuncParam() const;

	const Attribute * accept( Visitor & v ) const override { return v.visit( this ); }
private:
	Attribute * clone() const override { return new Attribute{ *this }; }

	/// Must be copied in ALL derived classes
	template<typename node_t>
	friend auto mutate(const node_t * node);
};



//=================================================================================================
/// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency
/// remove only if there is a better solution
/// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with
/// forward declarations
inline void increment( const class Attribute * node, Node::ref_type ref ) { node->increment( ref ); }
inline void decrement( const class Attribute * node, Node::ref_type ref ) { node->decrement( ref ); }
}

// Local Variables: //
// tab-width: 4 //
// mode: c++ //
// compile-command: "make install" //
// End: //
