Skip to content

Commit

Permalink
Move procedure createTypeDependencyGraph out of TypeEnvironmentAnalysis
Browse files Browse the repository at this point in the history
  • Loading branch information
tytus-metrycki committed May 8, 2020
1 parent 2bf055a commit 8f0ebf6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
41 changes: 22 additions & 19 deletions src/AstTypeEnvironmentAnalysis.cpp
Expand Up @@ -30,6 +30,28 @@

namespace souffle {

namespace {

Graph<AstQualifiedName> createTypeDependencyGraph(const std::vector<AstType*>& programTypes) {
Graph<AstQualifiedName> typeDependencyGraph;
for (const auto* astType : programTypes) {
if (auto type = dynamic_cast<const AstSubsetType*>(astType)) {
typeDependencyGraph.insert(type->getQualifiedName(), type->getBaseType());
} else if (dynamic_cast<const AstRecordType*>(astType) != nullptr) {
// do nothing
} else if (auto type = dynamic_cast<const AstUnionType*>(astType)) {
for (const auto& subtype : type->getTypes()) {
typeDependencyGraph.insert(type->getQualifiedName(), subtype);
}
} else {
fatal("unsupported type construct: %s", typeid(astType).name());
}
}
return typeDependencyGraph;
}

} // namespace

void TypeEnvironmentAnalysis::run(const AstTranslationUnit& translationUnit) {
const AstProgram& program = *translationUnit.getProgram();

Expand Down Expand Up @@ -105,25 +127,6 @@ void TypeEnvironmentAnalysis::linkTypes(const std::vector<AstType*>& programType
}
}

Graph<AstQualifiedName> TypeEnvironmentAnalysis::createTypeDependencyGraph(
const std::vector<AstType*>& programTypes) {
Graph<AstQualifiedName> typeDependencyGraph;
for (const auto* astType : programTypes) {
if (auto type = dynamic_cast<const AstSubsetType*>(astType)) {
typeDependencyGraph.insert(type->getQualifiedName(), type->getBaseType());
} else if (dynamic_cast<const AstRecordType*>(astType) != nullptr) {
// do nothing
} else if (auto type = dynamic_cast<const AstUnionType*>(astType)) {
for (const auto& subtype : type->getTypes()) {
typeDependencyGraph.insert(type->getQualifiedName(), subtype);
}
} else {
fatal("unsupported type construct: %s", typeid(astType).name());
}
}
return typeDependencyGraph;
}

void TypeEnvironmentAnalysis::analyseCyclicTypes(
const Graph<AstQualifiedName>& dependencyGraph, const std::vector<AstType*>& programTypes) {
for (const auto& astType : programTypes) {
Expand Down
5 changes: 0 additions & 5 deletions src/AstTypeEnvironmentAnalysis.h
Expand Up @@ -70,11 +70,6 @@ class TypeEnvironmentAnalysis : public AstAnalysis {
*/
void linkTypes(const std::vector<AstType*>& program);

/**
* Create a type dependency graph.
*/
Graph<AstQualifiedName> createTypeDependencyGraph(const std::vector<AstType*>& programTypes);

/**
* Check intersections of unions with primitive types.
*/
Expand Down

0 comments on commit 8f0ebf6

Please sign in to comment.