#pragma once

#include "ParRegions.h"
#include "SgUtils.h"
#include "errors.h"
#include "graph_calls.h"

void fillRegionIntervals(std::vector<ParallelRegion*> &regions);
void fillRegionArrays(std::vector<ParallelRegion*> &regions, const std::map<std::string, std::vector<FuncInfo*>> &allFuncInfo, const std::map<std::string, CommonBlock*> &commonBlocks);
void fillRegionFunctions(std::vector<ParallelRegion*> &regions, const std::map<std::string, std::vector<FuncInfo*>> &allFuncInfo);
bool checkRegions(const std::vector<ParallelRegion*> &regions, const std::map<std::string, std::vector<FuncInfo*>> &allFuncInfo, std::map<std::string, std::vector<Messages>> &SPF_messages);
int printCheckRegions(const char *fileName, const std::vector<ParallelRegion*> &regions, const std::map<std::string, std::vector<FuncInfo*>> &allFuncInfo);

bool checkRegionsResolving(const std::vector<ParallelRegion*> &regions, const std::map<std::string, std::vector<FuncInfo*>> &allFuncInfo, const std::map<std::string, CommonBlock*> &commonBlocks, std::map<std::string, std::vector<Messages>> &SPF_messages, bool sharedMemoryParallelization);
int resolveParRegions(std::vector<ParallelRegion*>& regions, const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo, std::map<std::string, std::vector<Messages>>& SPF_messages, bool sharedMemoryParallelization, std::map<std::string, std::map<int, std::set<std::string>>>& copyDecls);
void insertRealignsBeforeFragments(ParallelRegion* reg, SgFile* file, const std::set<DIST::Array*>& distrArrays, const std::map<DIST::Array*, std::set<DIST::Array*>>& arrayLinksByFuncCalls);

std::pair<SgSymbol*, SgSymbol*> copyArray(const std::pair<std::string, int>& place,
                                          const DIST::Array* array,
                                          const std::vector<ParallelRegionLines>& lines,
                                          const std::string& suffix,
                                          std::string& filename,
                                          std::map<std::string, std::map<int, std::set<std::string>>>& newDeclsToInclude,
                                          std::map<std::string, std::map<int, std::set<std::string>>>& copied);

const std::vector<const Variable*> getArraySynonyms(DIST::Array* array);