FLANG
FrontendAction.h
Go to the documentation of this file.
1//===- FrontendAction.h -----------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
12//===----------------------------------------------------------------------===//
13//
14// Coding style: https://mlir.llvm.org/getting_started/DeveloperGuide/
15//
16//===----------------------------------------------------------------------===//
17
18#ifndef FORTRAN_FRONTEND_FRONTENDACTION_H
19#define FORTRAN_FRONTEND_FRONTENDACTION_H
20
21#include "flang/Frontend/FrontendOptions.h"
22#include "llvm/Support/Error.h"
23
24namespace Fortran::frontend {
25class CompilerInstance;
26
29 FrontendInputFile currentInput;
30 CompilerInstance *instance;
31
32protected:
35
38 virtual void executeAction() = 0;
39
44 virtual bool shouldEraseOutputFiles();
45
50 virtual bool beginSourceFileAction() { return true; }
51
53
54public:
55 FrontendAction() : instance(nullptr) {}
56 virtual ~FrontendAction() = default;
57
60
61 CompilerInstance &getInstance() const {
62 assert(instance && "Compiler instance not registered!");
63 return *instance;
64 }
65
66 void setInstance(CompilerInstance *value) { instance = value; }
67
71
72 const FrontendInputFile &getCurrentInput() const { return currentInput; }
73
74 llvm::StringRef getCurrentFile() const {
75 assert(!currentInput.isEmpty() && "No current file!");
76 return currentInput.getFile();
77 }
78
79 llvm::StringRef getCurrentFileOrBufferName() const {
80 assert(!currentInput.isEmpty() && "No current file!");
81 return currentInput.isFile()
82 ? currentInput.getFile()
83 : currentInput.getBuffer()->getBufferIdentifier();
84 }
85 void setCurrentInput(const FrontendInputFile &currentIntput);
86
90
99 bool beginSourceFile(CompilerInstance &ci, const FrontendInputFile &input);
100
102 llvm::Error execute();
103
106 void endSourceFile();
107
109protected:
110 // Prescan the current input file. Return False if fatal errors are reported,
111 // True otherwise.
112 bool runPrescan();
113 // Parse the current input file. Return False if fatal errors are reported,
114 // True otherwise.
115 bool runParse(bool emitMessages);
116 // Run semantic checks for the current input file. Return False if fatal
117 // errors are reported, True otherwise.
118 bool runSemanticChecks();
119 // Generate run-time type information for derived types. This may lead to new
120 // semantic errors. Return False if fatal errors are reported, True
121 // otherwise.
122 bool generateRtTypeTables();
123
124 // Report fatal semantic errors. Return True if present, false otherwise.
125 bool reportFatalSemanticErrors();
126
127 // Report fatal scanning errors. Return True if present, false otherwise.
128 inline bool reportFatalScanningErrors() {
129 return reportFatalErrors("Could not scan %0");
130 }
131
132 // Report fatal parsing errors. Return True if present, false otherwise
133 inline bool reportFatalParsingErrors() {
134 return reportFatalErrors("Could not parse %0");
135 }
136
137private:
138 template <unsigned N>
139 bool reportFatalErrors(const char (&message)[N]);
140};
141
142} // namespace Fortran::frontend
143
144#endif // FORTRAN_FRONTEND_FRONTENDACTION_H
Definition: CompilerInstance.h:44
Abstract base class for actions which can be performed by the frontend.
Definition: FrontendAction.h:28
virtual bool shouldEraseOutputFiles()
Definition: FrontendAction.cpp:116
virtual bool beginSourceFileAction()
Definition: FrontendAction.h:50
bool beginSourceFile(CompilerInstance &ci, const FrontendInputFile &input)
Definition: FrontendAction.cpp:38
void endSourceFile()
Definition: FrontendAction.cpp:126
llvm::Error execute()
Run the action.
Definition: FrontendAction.cpp:120
An input file for the front end.
Definition: FrontendOptions.h:173