6c772ac40b
Includes like "../dir/file.h" should sort after local includes. This change fixes that and applies the new formatting. Now the order (in reverse) is: - system includes - includes from llvm or clang (this is from the default IncludeCategories) - includes of ../something - everything else Original-commit: flang-compiler/f18@324643d63a Reviewed-on: https://github.com/flang-compiler/f18/pull/52
92 lines
1.8 KiB
C++
92 lines
1.8 KiB
C++
#ifndef FORTRAN_LABEL_TABLE_H_
|
|
#define FORTRAN_LABEL_TABLE_H_
|
|
|
|
#include <cassert>
|
|
#include <stack>
|
|
|
|
namespace Fortran::semantics {
|
|
|
|
// Each statement label is in one of those groups
|
|
enum class LabelGroup
|
|
{
|
|
BranchTarget, ///< A label a possible branch target
|
|
Format, ///< A label on a FORMAT statement
|
|
Other ///< A label on another statement
|
|
};
|
|
|
|
|
|
//
|
|
// Hold all the labels of a Program Unit
|
|
//
|
|
// This is going to a integrated into the Scope/SymbolTable
|
|
// once we have it implemented. For now, I am just simulating
|
|
// scopes with LabelTable and LabelTableStack
|
|
//
|
|
class LabelTable
|
|
{
|
|
private:
|
|
|
|
struct Entry {
|
|
// TODO: what to put here
|
|
Fortran::parser::Provenance loc;
|
|
};
|
|
|
|
std::map<int,Entry> entries_ ;
|
|
|
|
public:
|
|
|
|
void add( int label , Fortran::parser::Provenance loc )
|
|
{
|
|
if (label<1 || label>99999) return ; // Hoops!
|
|
auto &entry = entries_[label] ;
|
|
entry.loc = loc ;
|
|
}
|
|
|
|
bool find(int label, Fortran::parser::Provenance &loc)
|
|
{
|
|
|
|
auto it = entries_.find(label);
|
|
if( it != entries_.end()) {
|
|
Entry & entry{it->second};
|
|
loc = entry.loc;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
|
|
}; // of class LabelTable
|
|
|
|
|
|
class LabelTableStack {
|
|
private:
|
|
std::stack<LabelTable*> stack ;
|
|
public:
|
|
LabelTable *PushLabelTable( LabelTable *table )
|
|
{
|
|
assert(table!=NULL);
|
|
stack.push(table);
|
|
return table;
|
|
}
|
|
|
|
void PopLabelTable( LabelTable *table )
|
|
{
|
|
assert( !stack.empty() ) ;
|
|
assert( stack.top() == table ) ;
|
|
stack.pop();
|
|
}
|
|
|
|
LabelTable & GetLabelTable() {
|
|
assert( !stack.empty() ) ;
|
|
return *stack.top() ;
|
|
}
|
|
|
|
bool NoLabelTable() {
|
|
return stack.empty() ;
|
|
}
|
|
|
|
}; // of class LabelTableStack
|
|
|
|
} // of namespace Fortran::semantics
|
|
|
|
#endif // FORTRAN_LABEL_TABLE_H_
|