souffle  2.0.2-371-g6315b36
BranchDeclaration.h
Go to the documentation of this file.
1 /*
2  * Souffle - A Datalog Compiler
3  * Copyright (c) 2020 The Souffle Developers. All rights reserved
4  * Licensed under the Universal Permissive License v 1.0 as shown at:
5  * - https://opensource.org/licenses/UPL
6  * - <souffle root>/licenses/SOUFFLE-UPL.txt
7  */
8 
9 /************************************************************************
10  *
11  * @file BranchDeclaration.h
12  *
13  * Defines the wrapper for a single branch in ADT declaration.
14  *
15  ***********************************************************************/
16 
17 #pragma once
18 
19 #include "ast/Attribute.h"
20 #include "ast/Node.h"
21 #include "parser/SrcLocation.h"
25 #include <iosfwd>
26 #include <string>
27 #include <utility>
28 #include <vector>
29 
30 namespace souffle::ast {
31 
32 /**
33  * @class BranchDeclaration
34  * @brief Wrapper for the single branch declaration (product type) inside ADT declaration.
35  *
36  * @param constructor An entity used to create a variant type. Can be though of as a name of the branch.
37  * @param fields Branch arguments and their types.
38  *
39  * A branch declaration corresponds to a product type and forms a part of ADT declaration.
40  * Currently it's required for all the branches to have unique names.
41  */
42 class BranchDeclaration : public Node {
43 public:
44  BranchDeclaration(std::string constructor, VecOwn<Attribute> fields, SrcLocation loc = {})
45  : Node(std::move(loc)), constructor(std::move(constructor)), fields(std::move(fields)){};
46 
47  const std::string& getConstructor() const {
48  return constructor;
49  }
50 
51  std::vector<Attribute*> getFields() {
52  return toPtrVector(fields);
53  }
54 
55  BranchDeclaration* clone() const override {
57  }
58 
59 protected:
60  void print(std::ostream& os) const override {
61  os << tfm::format("%s {%s}", constructor, join(fields, ", "));
62  }
63 
64 private:
65  std::string constructor;
67 };
68 
69 } // namespace souffle::ast
souffle::ast::BranchDeclaration
Wrapper for the single branch declaration (product type) inside ADT declaration.
Definition: BranchDeclaration.h:48
tinyformat::format
void format(std::ostream &out, const char *fmt)
Definition: tinyformat.h:1089
SrcLocation.h
souffle::ast::BranchDeclaration::print
void print(std::ostream &os) const override
Output to a given output stream.
Definition: BranchDeclaration.h:66
tinyformat.h
Attribute.h
souffle::ast::BranchDeclaration::constructor
std::string constructor
Definition: BranchDeclaration.h:71
souffle::clone
auto clone(const std::vector< A * > &xs)
Definition: ContainerUtil.h:172
ContainerUtil.h
souffle::join
detail::joined_sequence< Iter, Printer > join(const Iter &a, const Iter &b, const std::string &sep, const Printer &p)
Creates an object to be forwarded to some output stream for printing sequences of elements interspers...
Definition: StreamUtil.h:175
Node.h
souffle::ast::BranchDeclaration::BranchDeclaration
BranchDeclaration(std::string constructor, VecOwn< Attribute > fields, SrcLocation loc={})
Definition: BranchDeclaration.h:50
souffle::ast::BranchDeclaration::clone
BranchDeclaration * clone() const override
Create a clone (i.e.
Definition: BranchDeclaration.h:61
StreamUtil.h
souffle::ast::BranchDeclaration::fields
VecOwn< Attribute > fields
Definition: BranchDeclaration.h:72
souffle::ast::Node::Node
Node(SrcLocation loc={})
Definition: Node.h:42
souffle::ast::BranchDeclaration::getFields
std::vector< Attribute * > getFields()
Definition: BranchDeclaration.h:57
souffle::ast::Node::getSrcLoc
const SrcLocation & getSrcLoc() const
Return source location of the Node.
Definition: Node.h:46
souffle::ast
Definition: Aggregator.h:35
souffle::ast::BranchDeclaration::getConstructor
const std::string & getConstructor() const
Definition: BranchDeclaration.h:53
souffle::toPtrVector
std::vector< T * > toPtrVector(const std::vector< std::unique_ptr< T >> &v)
A utility function enabling the creation of a vector of pointers.
Definition: ContainerUtil.h:146
souffle::VecOwn
std::vector< Own< A > > VecOwn
Definition: ContainerUtil.h:45