Fix warnings
This commit is contained in:
@@ -1,19 +1,8 @@
|
|||||||
#include <string>
|
|
||||||
#include <set>
|
|
||||||
#include <map>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "Utils/SgUtils.h"
|
#include "Utils/SgUtils.h"
|
||||||
#include "set_implicit_none.h"
|
#include "set_implicit_none.h"
|
||||||
#include <LoopAnalyzer/loop_analyzer.h>
|
|
||||||
|
|
||||||
using std::vector;
|
using std::vector;
|
||||||
using std::map;
|
using std::map;
|
||||||
using std::multimap;
|
|
||||||
using std::set;
|
|
||||||
using std::make_pair;
|
|
||||||
using std::string;
|
|
||||||
using std::to_string;
|
|
||||||
|
|
||||||
map<char, SgType*> types;
|
map<char, SgType*> types;
|
||||||
vector<SgSymbol*> allVars;
|
vector<SgSymbol*> allVars;
|
||||||
@@ -24,9 +13,11 @@ void InitTypes();
|
|||||||
void FillCommonTypes();
|
void FillCommonTypes();
|
||||||
void FunctionImplicitCheck(SgStatement* function);
|
void FunctionImplicitCheck(SgStatement* function);
|
||||||
|
|
||||||
void ImplicitCheck(SgFile* file) {
|
void ImplicitCheck(SgFile* file)
|
||||||
|
{
|
||||||
|
|
||||||
for (int funcNum = 0; funcNum < file->numberOfFunctions(); funcNum++) {
|
for (int funcNum = 0; funcNum < file->numberOfFunctions(); funcNum++)
|
||||||
|
{
|
||||||
SgStatement* function = file->functions(funcNum);
|
SgStatement* function = file->functions(funcNum);
|
||||||
FunctionImplicitCheck(function);
|
FunctionImplicitCheck(function);
|
||||||
}
|
}
|
||||||
@@ -34,22 +25,27 @@ void ImplicitCheck(SgFile* file) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FunctionImplicitCheck(SgStatement* function) {
|
void FunctionImplicitCheck(SgStatement* function)
|
||||||
|
{
|
||||||
auto implicitNoneDeclaration = new SgStatement(IMPL_DECL);
|
auto implicitNoneDeclaration = new SgStatement(IMPL_DECL);
|
||||||
auto hasImplicitNone = false;
|
auto hasImplicitNone = false;
|
||||||
|
|
||||||
InitTypes();
|
InitTypes();
|
||||||
FillCommonTypes();
|
FillCommonTypes();
|
||||||
|
|
||||||
for (SgStatement* i = function->lexNext(); i = i->lexNext(); i != NULL) {
|
for (SgStatement* statement = function->lexNext(); statement = statement->lexNext(); statement != NULL)
|
||||||
|
{
|
||||||
if (i->variant() == IMPL_DECL) {
|
if (statement->variant() == IMPL_DECL)
|
||||||
SgImplicitStmt* implicitSt = isSgImplicitStmt(i);
|
{
|
||||||
if (implicitSt) {
|
SgImplicitStmt* implicitSt = isSgImplicitStmt(statement);
|
||||||
|
if (implicitSt)
|
||||||
|
{
|
||||||
int numberOfTypes = implicitSt->numberOfImplicitTypes();
|
int numberOfTypes = implicitSt->numberOfImplicitTypes();
|
||||||
|
|
||||||
if (numberOfTypes > 0) {
|
if (numberOfTypes > 0)
|
||||||
for (int j = 0; j < numberOfTypes; j++) {
|
{
|
||||||
|
for (int j = 0; j < numberOfTypes; j++)
|
||||||
|
{
|
||||||
SgType* type = implicitSt->implicitType(j);
|
SgType* type = implicitSt->implicitType(j);
|
||||||
SgExpression* letters = implicitSt->implicitRangeList(j);
|
SgExpression* letters = implicitSt->implicitRangeList(j);
|
||||||
|
|
||||||
@@ -57,15 +53,22 @@ void FunctionImplicitCheck(SgStatement* function) {
|
|||||||
types['o'] = type;
|
types['o'] = type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
hasImplicitNone = true;
|
hasImplicitNone = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (statement->variant() == CONTAINS_STMT || isSgExecutableStatement(statement) != NULL)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (SgSymbol* symbol = function->symbol(); symbol != NULL; symbol = symbol->next()) {
|
for (SgSymbol* symbol = function->symbol(); symbol != NULL; symbol = symbol->next())
|
||||||
if (symbol != NULL && symbol->declaredInStmt() != NULL) {
|
{
|
||||||
|
if (symbol != NULL && symbol->declaredInStmt() != NULL)
|
||||||
|
{
|
||||||
allVars.push_back(symbol);
|
allVars.push_back(symbol);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -74,36 +77,38 @@ void FunctionImplicitCheck(SgStatement* function) {
|
|||||||
{
|
{
|
||||||
vector<SgStatement*> _;
|
vector<SgStatement*> _;
|
||||||
SgStatement* declaredIn = declaratedInStmt(var, &_, false);
|
SgStatement* declaredIn = declaratedInStmt(var, &_, false);
|
||||||
if (declaredIn == NULL) {
|
if (declaredIn == NULL)
|
||||||
|
{
|
||||||
|
char c = var->identifier()[0];
|
||||||
|
|
||||||
|
if (types.find(c) != types.end())
|
||||||
|
{
|
||||||
|
var->setType(types[c]);
|
||||||
|
}
|
||||||
|
|
||||||
varsWithoutDecl.push_back(var);
|
varsWithoutDecl.push_back(var);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto var : varsWithoutDecl) {
|
makeDeclaration(varsWithoutDecl, function, NULL);
|
||||||
vector<SgSymbol*> test = { var };
|
|
||||||
char c = var->identifier()[0];
|
|
||||||
|
|
||||||
if (types.find(c) != types.end()) {
|
if (!hasImplicitNone)
|
||||||
test[0]->setType(types[c]);
|
{
|
||||||
}
|
for (SgStatement* i = function->lexNext(); i != NULL;)
|
||||||
|
{
|
||||||
makeDeclaration(function, test);
|
if (i->variant() == IMPL_DECL)
|
||||||
}
|
{
|
||||||
|
|
||||||
if (!hasImplicitNone) {
|
|
||||||
for (SgStatement* i = function->lexNext(); i != NULL;) {
|
|
||||||
if (i->variant() == IMPL_DECL) {
|
|
||||||
auto tmp = i;
|
auto tmp = i;
|
||||||
i = i->lexNext();
|
i = i->lexNext();
|
||||||
tmp->deleteStmt();
|
tmp->deleteStmt();
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
i = i->lexNext();
|
i = i->lexNext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto firstRealStatementOfFile = function->lexNext();
|
function->insertStmtBefore(*implicitNoneDeclaration, *function);
|
||||||
firstRealStatementOfFile->insertStmtBefore(*implicitNoneDeclaration, *(firstRealStatementOfFile->controlParent()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("%s", function->unparse());
|
printf("%s", function->unparse());
|
||||||
@@ -111,21 +116,28 @@ void FunctionImplicitCheck(SgStatement* function) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitTypes() {
|
void InitTypes()
|
||||||
for (char i = 'a'; i <= 'z'; i++) {
|
{
|
||||||
|
for (char i = 'a'; i <= 'z'; i++)
|
||||||
|
{
|
||||||
types[i] = NULL;
|
types[i] = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FillCommonTypes() {
|
void FillCommonTypes()
|
||||||
for (char i: commonIntLetters) {
|
{
|
||||||
if (types[i] == NULL) {
|
for (char i: commonIntLetters)
|
||||||
|
{
|
||||||
|
if (types[i] == NULL)
|
||||||
|
{
|
||||||
types[i] = new SgType(T_INT);
|
types[i] = new SgType(T_INT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto i : types) {
|
for (auto i : types)
|
||||||
if (i.second == NULL) {
|
{
|
||||||
|
if (i.second == NULL)
|
||||||
|
{
|
||||||
types[i.first] = new SgType(T_FLOAT);
|
types[i.first] = new SgType(T_FLOAT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user