Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion C/sema/SemanticModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ TypeInfo SemanticModel::typeInfoOf_CORE(const SyntaxNode* node)
if (it != P->tyInfoByNode_.end())
return it->second;
return TypeInfo(compilation()->canonicalErrorType(),
TypeInfo::TypeOrigin::Error);
TypeInfo::Origin::Error);
}

TypeInfo SemanticModel::typeInfoOf(const ExpressionSyntax* node) const
Expand Down
207 changes: 111 additions & 96 deletions C/sema/TypeChecker.cpp

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions C/sema/TypeChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,19 +221,17 @@ class PSY_C_INTERNAL_API TypeChecker final : protected SyntaxVisitor
//--------//
virtual Action visitTypeName(const TypeNameSyntax*) override;

void createTypeInfo(const SyntaxNode*, const Type*, TypeInfo::TypeOrigin);
void createTypeInfo(const SyntaxNode*, const Type*, TypeInfo::Origin);
Action typeChecked(const ExpressionSyntax*,
const Type*,
TypeInfo::TypeOrigin = TypeInfo::TypeOrigin::Expression);
TypeInfo::Origin = TypeInfo::Origin::ExpressionTyping);
Action typeCheckError(const SyntaxNode*);

static const Type* resolved(const Type* ty);
static const Type* unqualifiedAndResolved(const Type* ty);

const Type* typeOfStringLiteral(StringLiteral::EncodingPrefix encodingSuffix);

void determineParameterListForm(FunctionDeclarationSymbol* func);

bool isNULLPointerConstant(const SyntaxNode* node);
bool isAssignableType(const Type* ty, const SyntaxNode* node);
bool isTypeAssignableFromOtherType(const Type* ty,
Expand Down
27 changes: 23 additions & 4 deletions C/sema/TypeInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,36 @@
using namespace psy;
using namespace C;

TypeInfo::TypeInfo(const Type* ty, TypeOrigin tyOrig)
TypeInfo::TypeInfo(const Type* ty, Origin orig)
: ty_(ty)
, tyOrig_(tyOrig)
, orig_(orig)
, undergoneConv_(UndergoneConversion::No)
{}

TypeInfo::TypeInfo(const Type* ty,
Origin tyOrig,
UndergoneConversion undergoneConv)
: ty_(ty)
, orig_(tyOrig)
, undergoneConv_(undergoneConv)
{}

TypeInfo::~TypeInfo()
{}

TypeInfo::TypeOrigin TypeInfo::typeOrigin() const
TypeInfo::Origin TypeInfo::origin() const
{
return orig_;
}

void TypeInfo::markAsUndergoneConversion()
{
undergoneConv_ = UndergoneConversion::Yes;
}

TypeInfo::UndergoneConversion TypeInfo::undergoneConversion() const
{
return tyOrig_;
return undergoneConv_;
}

const Type* TypeInfo::type() const
Expand Down
29 changes: 22 additions & 7 deletions C/sema/TypeInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,30 @@ class PSY_C_API TypeInfo final
~TypeInfo();

/**
* The alternatives of a TypeOrigin.
* The alternatives of a type origin.
*/
enum class TypeOrigin : std::uint8_t
enum class Origin : std::uint8_t
{
Error,
Expression,
ExpressionTyping,
TypeName,
};

/**
* The TypeOrigin of the Type of \c this TypeInfo.
* The origin of the Type of \c this TypeInfo.
*/
TypeOrigin typeOrigin() const;
Origin origin() const;

/**
* Wheter the type has undergone conversion.
**/
enum class UndergoneConversion : std::uint8_t
{
No,
Yes,
};

UndergoneConversion undergoneConversion() const;

/**
* The Type of \c this TypeInfo.
Expand All @@ -63,11 +74,15 @@ class PSY_C_API TypeInfo final
PSY_GRANT_INTERNAL_ACCESS(TypeChecker);
PSY_GRANT_INTERNAL_ACCESS(SemanticModel);

void markAsUndergoneConversion();

private:
TypeInfo(const Type* ty, TypeOrigin tyOrig);
TypeInfo(const Type* ty, Origin orig);
TypeInfo(const Type* ty, Origin orig, UndergoneConversion undergoneConv);

const Type* ty_;
TypeOrigin tyOrig_;
Origin orig_;
UndergoneConversion undergoneConv_;
};

} // C
Expand Down
8 changes: 4 additions & 4 deletions C/sema/TypedefNameTypeResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ const Type* TypedefNameTypeResolver::resolve(const Type* ty)
auto resolvedTy = resolve(retTy);
if (resolvedTy != retTy)
funcTy->setReturnType(resolvedTy);
const auto parms = funcTy->parameterTypes();
const auto parmsSize = parms.size();
for (FunctionType::ParameterTypes::size_type idx = 0; idx < parmsSize; ++idx) {
const Type* parmTy = parms[idx];
const auto parmsTys = funcTy->parameterTypes();
const auto parmsSz = parmsTys.size();
for (FunctionType::ParameterTypes::size_type idx = 0; idx < parmsSz; ++idx) {
const Type* parmTy = parmsTys[idx];
resolvedTy = resolve(parmTy);
if (resolvedTy != parmTy)
funcTy->setParameterType(idx, resolvedTy);
Expand Down
6 changes: 4 additions & 2 deletions C/tests/SemanticModelTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,8 @@ void SemanticModelTester::case0503()
auto tyInfo = semaModel->typeInfoOf(exprNode);
auto ty = tyInfo.type();
PSY_EXPECT_TRUE(ty);
PSY_EXPECT_EQ_ENU(ty->kind(), TypeKind::Function, TypeKind);
PSY_EXPECT_EQ_ENU(ty->kind(), TypeKind::Pointer, TypeKind);
PSY_EXPECT_EQ_ENU(ty->asPointerType()->referencedType()->kind(), TypeKind::Function, TypeKind);

exprNode = exprNodeByText["f ( )"];
PSY_EXPECT_TRUE(exprNode);
Expand All @@ -1199,7 +1200,8 @@ void SemanticModelTester::case0504()
auto tyInfo = semaModel->typeInfoOf(exprNode);
auto ty = tyInfo.type();
PSY_EXPECT_TRUE(ty);
PSY_EXPECT_EQ_ENU(ty->kind(), TypeKind::Function, TypeKind);
PSY_EXPECT_EQ_ENU(ty->kind(), TypeKind::Pointer, TypeKind);
PSY_EXPECT_EQ_ENU(ty->asPointerType()->referencedType()->kind(), TypeKind::Function, TypeKind);

exprNode = exprNodeByText["f ( )"];
PSY_EXPECT_TRUE(exprNode);
Expand Down
Loading
Loading