souffle  2.0.2-371-g6315b36
SubroutineArgument.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 SubroutineArgument.h
12  *
13  * Defines the subroutine argument class
14  *
15  ***********************************************************************/
16 
17 #pragma once
18 
19 #include "ast/Argument.h"
20 #include "ast/Node.h"
21 #include "parser/SrcLocation.h"
22 #include <cstddef>
23 #include <ostream>
24 #include <string>
25 #include <utility>
26 
27 namespace souffle::ast {
28 
29 /**
30  * @class SubroutineArgument
31  * @brief Defines the argument class for subrountines
32  */
33 class SubroutineArgument : public Argument {
34 public:
35  SubroutineArgument(size_t index, SrcLocation loc = {}) : Argument(std::move(loc)), index(index) {}
36 
37  /** Return argument index */
38  size_t getNumber() const {
39  return index;
40  }
41 
42  SubroutineArgument* clone() const override {
43  return new SubroutineArgument(index, getSrcLoc());
44  }
45 
46 protected:
47  void print(std::ostream& os) const override {
48  os << "arg(" << index << ")";
49  }
50 
51  bool equal(const Node& node) const override {
52  const auto& other = static_cast<const SubroutineArgument&>(node);
53  return index == other.index;
54  }
55 
56 private:
57  /** Index of subroutine argument */
58  size_t index;
59 };
60 
61 } // namespace souffle::ast
SrcLocation.h
souffle::ast::SubroutineArgument
Defines the argument class for subrountines.
Definition: SubroutineArgument.h:39
souffle::ast::SubroutineArgument::index
size_t index
Index of subroutine argument.
Definition: SubroutineArgument.h:64
souffle::ast::SubroutineArgument::SubroutineArgument
SubroutineArgument(size_t index, SrcLocation loc={})
Definition: SubroutineArgument.h:41
Argument.h
souffle::ast::SubroutineArgument::clone
SubroutineArgument * clone() const override
Create clone.
Definition: SubroutineArgument.h:48
souffle::ast::SubroutineArgument::getNumber
size_t getNumber() const
Return argument index.
Definition: SubroutineArgument.h:44
Node.h
souffle::ast::Node
Abstract class for syntactic elements in an input program.
Definition: Node.h:40
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::SubroutineArgument::print
void print(std::ostream &os) const override
Output to a given output stream.
Definition: SubroutineArgument.h:53
souffle::ast::SubroutineArgument::equal
bool equal(const Node &node) const override
Abstract equality check for two AST nodes.
Definition: SubroutineArgument.h:57