souffle  2.0.2-371-g6315b36
Analysis.h
Go to the documentation of this file.
1 /*
2  * Souffle - A Datalog Compiler
3  * Copyright (c) 2015, Oracle and/or its affiliates. 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 Analysis.h
12  *
13  * Defines an interface for AST analysis
14  *
15  ***********************************************************************/
16 
17 #pragma once
18 
19 #include <ostream>
20 #include <string>
21 #include <utility>
22 
23 namespace souffle::ast {
24 
25 class TranslationUnit;
26 
27 namespace analysis {
28 
29 /**
30  * Abstract class for a AST Analysis.
31  */
32 class Analysis {
33 public:
34  Analysis(std::string identifier) : identifier(std::move(identifier)) {}
35  virtual ~Analysis() = default;
36 
37  /** run analysis for a Ast translation unit */
38  virtual void run(const TranslationUnit& /*translationUnit*/) = 0;
39 
40  /** print the analysis result in HTML format */
41  virtual void print(std::ostream&) const {}
42 
43  /** @brief get name of the analysis */
44  virtual const std::string& getName() const {
45  return identifier;
46  }
47 
48  /** define output stream operator */
49  friend std::ostream& operator<<(std::ostream& out, const Analysis& other) {
50  other.print(out);
51  return out;
52  }
53 
54 protected:
55  const std::string identifier;
56 };
57 
58 } // namespace analysis
59 } // namespace souffle::ast
souffle::ast::analysis::Analysis::identifier
const std::string identifier
Definition: Analysis.h:61
souffle::ast::analysis::Analysis::operator<<
friend std::ostream & operator<<(std::ostream &out, const Analysis &other)
define output stream operator
Definition: Analysis.h:55
souffle::ast::analysis::Analysis::Analysis
Analysis(std::string identifier)
Definition: Analysis.h:40
souffle::ast::analysis::Analysis::print
virtual void print(std::ostream &) const
print the analysis result in HTML format
Definition: Analysis.h:47
souffle::ast::analysis::Analysis::getName
virtual const std::string & getName() const
get name of the analysis
Definition: Analysis.h:50
souffle::ast::TranslationUnit
Translation unit class for the translation pipeline.
Definition: TranslationUnit.h:51
souffle::ast::analysis::Analysis::run
virtual void run(const TranslationUnit &)=0
run analysis for a Ast translation unit
souffle::ast::analysis::Analysis
Abstract class for a AST Analysis.
Definition: Analysis.h:38
std
Definition: Brie.h:3053
souffle::ast::analysis::Analysis::~Analysis
virtual ~Analysis()=default
souffle::ast
Definition: Aggregator.h:35