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 FillCommonTypes();
|
||||
void FunctionImplicitCheck(SgStatement* function);
|
||||
|
||||
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 hasImplicitNone = false;
|
||||
|
||||
InitTypes();
|
||||
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) {
|
||||
SgImplicitStmt* implicitSt = isSgImplicitStmt(i);
|
||||
@@ -44,8 +54,7 @@ void ImplicitCheck(SgFile* file) {
|
||||
SgExpression* letters = implicitSt->implicitRangeList(j);
|
||||
|
||||
// get real letters
|
||||
types['a'] = type;
|
||||
printf("%s\n", letters->unparse());
|
||||
types['o'] = type;
|
||||
}
|
||||
}
|
||||
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)
|
||||
{
|
||||
SgStatement* declaredIn = declaratedInStmt(var);
|
||||
vector<SgStatement*> _;
|
||||
SgStatement* declaredIn = declaratedInStmt(var, &_, false);
|
||||
if (declaredIn == NULL) {
|
||||
varsWithoutDecl.push_back(var);
|
||||
}
|
||||
}
|
||||
|
||||
// create decl
|
||||
// delete implicit
|
||||
for (auto var : varsWithoutDecl) {
|
||||
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) {
|
||||
for (SgStatement* i = file->firstStatement(); ; i != NULL) {
|
||||
for (SgStatement* i = function->lexNext(); i != NULL;) {
|
||||
if (i->variant() == IMPL_DECL) {
|
||||
auto tmp = i;
|
||||
i = i->lexNext();
|
||||
tmp->deleteStmt();
|
||||
}
|
||||
else {
|
||||
i = i->lexNext();
|
||||
}
|
||||
}
|
||||
|
||||
auto firstRealStatementOfFile = file->firstStatement()->lexNext()->lexNext();
|
||||
auto firstRealStatementOfFile = function->lexNext();
|
||||
firstRealStatementOfFile->insertStmtBefore(*implicitNoneDeclaration, *(firstRealStatementOfFile->controlParent()));
|
||||
}
|
||||
|
||||
printf("%s", file->firstStatement()->lexNext()->unparse());
|
||||
printf("%s", function->unparse());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user