Skip to content

Commit

Permalink
Moved type-attribute-getter to its own method.
Browse files Browse the repository at this point in the history
  • Loading branch information
azreika committed Nov 5, 2020
1 parent 053069a commit 6d95796
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
43 changes: 24 additions & 19 deletions src/ast/analysis/Type.cpp
Expand Up @@ -884,26 +884,31 @@ bool TypeAnalysis::isMultiResultFunctor(const Functor& functor) {
fatal("Missing functor type.");
}

IntrinsicFunctors TypeAnalysis::validOverloads(const IntrinsicFunctor& inf) const {
auto typeAttrs = [&](const Argument* arg) -> std::set<TypeAttribute> {
std::set<TypeAttribute> tyAttrs;
if (const auto* inf = dynamic_cast<const IntrinsicFunctor*>(arg)) {
if (hasValidTypeInfo(inf)) {
tyAttrs.insert(getFunctorReturnType(inf));
return tyAttrs;
}
std::set<TypeAttribute> TypeAnalysis::getTypeAttributes(const Argument* arg) const {
std::set<TypeAttribute> typeAttributes;

if (const auto* inf = dynamic_cast<const IntrinsicFunctor*>(arg)) {
// intrinsic functor type is its return type if its set
if (hasValidTypeInfo(inf)) {
typeAttributes.insert(getFunctorReturnType(inf));
return typeAttributes;
}
auto&& types = getTypes(arg);
if (types.isAll())
return {TypeAttribute::Signed, TypeAttribute::Unsigned, TypeAttribute::Float,
TypeAttribute::Symbol, TypeAttribute::Record};

for (auto&& ty : types)
tyAttrs.insert(getTypeAttribute(ty));
return tyAttrs;
};
auto retTys = typeAttrs(&inf);
auto argTys = map(inf.getArguments(), typeAttrs);
}

const auto& types = getTypes(arg);
if (types.isAll()) {
return {TypeAttribute::Signed, TypeAttribute::Unsigned, TypeAttribute::Float, TypeAttribute::Symbol,
TypeAttribute::Record};
}
for (const auto& type : types) {
typeAttributes.insert(getTypeAttribute(type));
}
return typeAttributes;
}

IntrinsicFunctors TypeAnalysis::validOverloads(const IntrinsicFunctor& inf) const {
auto retTys = getTypeAttributes(&inf);
auto argTys = map(inf.getArguments(), [&](const Argument* arg) { return getTypeAttributes(arg); });

IntrinsicFunctors functorInfos = contains(functorInfo, &inf)
? functorBuiltIn(getPolymorphicOperator(&inf))
Expand Down
4 changes: 3 additions & 1 deletion src/ast/analysis/Type.h
Expand Up @@ -26,6 +26,7 @@
#include "ast/analysis/Analysis.h"
#include "ast/analysis/TypeSystem.h"
#include <memory>
#include <set>
#include <sstream>
#include <string>
#include <vector>
Expand Down Expand Up @@ -67,9 +68,10 @@ class TypeAnalysis : public Analysis {
// Checks whether an argument has been assigned a valid type
bool hasValidTypeInfo(const Argument* argument) const;

std::set<TypeAttribute> getTypeAttributes(const Argument* arg) const;

/** -- Functor-related methods -- */
IntrinsicFunctors validOverloads(const ast::IntrinsicFunctor& inf) const;

TypeAttribute getFunctorReturnType(const Functor* functor) const;
TypeAttribute getFunctorArgType(const Functor* functor, const size_t idx) const;
const std::vector<TypeAttribute>& getFunctorArgTypes(const UserDefinedFunctor& udf) const;
Expand Down

0 comments on commit 6d95796

Please sign in to comment.