WIP: add deleting implicit stmts aninserting decls
This commit is contained in:
@@ -22,16 +22,26 @@ const char commonIntLetters[6] = {'i', 'j', 'k', 'm', 'n', 'l'};
|
|||||||
|
|
||||||
void InitTypes();
|
void InitTypes();
|
||||||
void FillCommonTypes();
|
void FillCommonTypes();
|
||||||
|
void FunctionImplicitCheck(SgStatement* function);
|
||||||
|
|
||||||
void ImplicitCheck(SgFile* file) {
|
void ImplicitCheck(SgFile* file) {
|
||||||
|
|
||||||
|
for (int funcNum = 0; funcNum < file->numberOfFunctions(); funcNum++) {
|
||||||
|
SgStatement* function = file->functions(funcNum);
|
||||||
|
FunctionImplicitCheck(function);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 = file->firstStatement(); i = i->lexNext(); i != NULL) {
|
for (SgStatement* i = function->lexNext(); i = i->lexNext(); i != NULL) {
|
||||||
|
|
||||||
if (i->variant() == IMPL_DECL) {
|
if (i->variant() == IMPL_DECL) {
|
||||||
SgImplicitStmt* implicitSt = isSgImplicitStmt(i);
|
SgImplicitStmt* implicitSt = isSgImplicitStmt(i);
|
||||||
@@ -44,8 +54,7 @@ void ImplicitCheck(SgFile* file) {
|
|||||||
SgExpression* letters = implicitSt->implicitRangeList(j);
|
SgExpression* letters = implicitSt->implicitRangeList(j);
|
||||||
|
|
||||||
// get real letters
|
// get real letters
|
||||||
types['a'] = type;
|
types['o'] = type;
|
||||||
printf("%s\n", letters->unparse());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -55,34 +64,49 @@ void ImplicitCheck(SgFile* file) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// get all vars
|
for (SgSymbol* symbol = function->symbol(); symbol != NULL; symbol = symbol->next()) {
|
||||||
|
if (symbol != NULL && symbol->declaredInStmt() != NULL) {
|
||||||
|
allVars.push_back(symbol);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (auto var : allVars)
|
for (auto var : allVars)
|
||||||
{
|
{
|
||||||
SgStatement* declaredIn = declaratedInStmt(var);
|
vector<SgStatement*> _;
|
||||||
|
SgStatement* declaredIn = declaratedInStmt(var, &_, false);
|
||||||
if (declaredIn == NULL) {
|
if (declaredIn == NULL) {
|
||||||
varsWithoutDecl.push_back(var);
|
varsWithoutDecl.push_back(var);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// create decl
|
for (auto var : varsWithoutDecl) {
|
||||||
// delete implicit
|
vector<SgSymbol*> test = { var };
|
||||||
|
char c = var->identifier()[0];
|
||||||
|
|
||||||
|
if (types.find(c) != types.end()) {
|
||||||
|
test[0]->setType(types[c]);
|
||||||
|
}
|
||||||
|
|
||||||
|
makeDeclaration(function, test);
|
||||||
|
}
|
||||||
|
|
||||||
if (!hasImplicitNone) {
|
if (!hasImplicitNone) {
|
||||||
for (SgStatement* i = file->firstStatement(); ; i != NULL) {
|
for (SgStatement* i = function->lexNext(); i != NULL;) {
|
||||||
if (i->variant() == IMPL_DECL) {
|
if (i->variant() == IMPL_DECL) {
|
||||||
auto tmp = i;
|
auto tmp = i;
|
||||||
i = i->lexNext();
|
i = i->lexNext();
|
||||||
tmp->deleteStmt();
|
tmp->deleteStmt();
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
i = i->lexNext();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto firstRealStatementOfFile = file->firstStatement()->lexNext()->lexNext();
|
auto firstRealStatementOfFile = function->lexNext();
|
||||||
firstRealStatementOfFile->insertStmtBefore(*implicitNoneDeclaration, *(firstRealStatementOfFile->controlParent()));
|
firstRealStatementOfFile->insertStmtBefore(*implicitNoneDeclaration, *(firstRealStatementOfFile->controlParent()));
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("%s", file->firstStatement()->lexNext()->unparse());
|
printf("%s", function->unparse());
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user