Skip to content

Commit

Permalink
introduce TagTypeDeclaration (and rename all declaration symbols) (#…
Browse files Browse the repository at this point in the history
…137)

* add TagTypeDeclaration

* rename files

* ...SymK -> ...K rename

* #directives
  • Loading branch information
ltcmelo authored Aug 24, 2024
1 parent 6bcc2c3 commit 427fb23
Show file tree
Hide file tree
Showing 61 changed files with 1,123 additions and 909 deletions.
55 changes: 29 additions & 26 deletions C/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,32 +141,35 @@ set(CFE_SOURCES
${PROJECT_SOURCE_DIR}/symbols/Symbol_TranslationUnit.h
${PROJECT_SOURCE_DIR}/symbols/Symbol_Declaration.cpp
${PROJECT_SOURCE_DIR}/symbols/Symbol_Declaration.h
${PROJECT_SOURCE_DIR}/symbols/DeclarationSymbolKind.h
${PROJECT_SOURCE_DIR}/symbols/DeclarationSymbol_Function.cpp
${PROJECT_SOURCE_DIR}/symbols/DeclarationSymbol_Function.h
${PROJECT_SOURCE_DIR}/symbols/DeclarationSymbol_Object.cpp
${PROJECT_SOURCE_DIR}/symbols/DeclarationSymbol_Object.h
${PROJECT_SOURCE_DIR}/symbols/DeclarationSymbol_Type.cpp
${PROJECT_SOURCE_DIR}/symbols/DeclarationSymbol_Type.h
${PROJECT_SOURCE_DIR}/symbols/ObjectDeclarationSymbolKind.h
${PROJECT_SOURCE_DIR}/symbols/ObjectDeclarationSymbol_Enumerator.cpp
${PROJECT_SOURCE_DIR}/symbols/ObjectDeclarationSymbol_Enumerator.h
${PROJECT_SOURCE_DIR}/symbols/ObjectDeclarationSymbol_Field.cpp
${PROJECT_SOURCE_DIR}/symbols/ObjectDeclarationSymbol_Field.h
${PROJECT_SOURCE_DIR}/symbols/ObjectDeclarationSymbol_Parameter.cpp
${PROJECT_SOURCE_DIR}/symbols/ObjectDeclarationSymbol_Parameter.h
${PROJECT_SOURCE_DIR}/symbols/ObjectDeclarationSymbol_Variable.cpp
${PROJECT_SOURCE_DIR}/symbols/ObjectDeclarationSymbol_Variable.h
${PROJECT_SOURCE_DIR}/symbols/TypeDeclarationSymbolKind.h
${PROJECT_SOURCE_DIR}/symbols/TypeDeclarationSymbol__IMPL__.inc
${PROJECT_SOURCE_DIR}/symbols/TypeDeclarationSymbol_Enum.cpp
${PROJECT_SOURCE_DIR}/symbols/TypeDeclarationSymbol_Enum.h
${PROJECT_SOURCE_DIR}/symbols/TypeDeclarationSymbol_Struct.cpp
${PROJECT_SOURCE_DIR}/symbols/TypeDeclarationSymbol_Struct.h
${PROJECT_SOURCE_DIR}/symbols/TypeDeclarationSymbol_Typedef.cpp
${PROJECT_SOURCE_DIR}/symbols/TypeDeclarationSymbol_Typedef.h
${PROJECT_SOURCE_DIR}/symbols/TypeDeclarationSymbol_Union.cpp
${PROJECT_SOURCE_DIR}/symbols/TypeDeclarationSymbol_Union.h
${PROJECT_SOURCE_DIR}/symbols/DeclarationKind.h
${PROJECT_SOURCE_DIR}/symbols/Declaration_Function.cpp
${PROJECT_SOURCE_DIR}/symbols/Declaration_Function.h
${PROJECT_SOURCE_DIR}/symbols/Declaration_Object.cpp
${PROJECT_SOURCE_DIR}/symbols/Declaration_Object.h
${PROJECT_SOURCE_DIR}/symbols/Declaration_Type.cpp
${PROJECT_SOURCE_DIR}/symbols/Declaration_Type.h
${PROJECT_SOURCE_DIR}/symbols/ObjectDeclarationKind.h
${PROJECT_SOURCE_DIR}/symbols/ObjectDeclaration_Enumerator.cpp
${PROJECT_SOURCE_DIR}/symbols/ObjectDeclaration_Enumerator.h
${PROJECT_SOURCE_DIR}/symbols/ObjectDeclaration_Field.cpp
${PROJECT_SOURCE_DIR}/symbols/ObjectDeclaration_Field.h
${PROJECT_SOURCE_DIR}/symbols/ObjectDeclaration_Parameter.cpp
${PROJECT_SOURCE_DIR}/symbols/ObjectDeclaration_Parameter.h
${PROJECT_SOURCE_DIR}/symbols/ObjectDeclaration_Variable.cpp
${PROJECT_SOURCE_DIR}/symbols/ObjectDeclaration_Variable.h
${PROJECT_SOURCE_DIR}/symbols/TypeDeclarationKind.h
${PROJECT_SOURCE_DIR}/symbols/TypeDeclaration__IMPL__.inc
${PROJECT_SOURCE_DIR}/symbols/TypeDeclaration_Tag.h
${PROJECT_SOURCE_DIR}/symbols/TypeDeclaration_Tag.cpp
${PROJECT_SOURCE_DIR}/symbols/TypeDeclaration_Typedef.cpp
${PROJECT_SOURCE_DIR}/symbols/TypeDeclaration_Typedef.h
${PROJECT_SOURCE_DIR}/symbols/TagTypeDeclarationKind.h
${PROJECT_SOURCE_DIR}/symbols/TagTypeDeclaration_Enum.cpp
${PROJECT_SOURCE_DIR}/symbols/TagTypeDeclaration_Enum.h
${PROJECT_SOURCE_DIR}/symbols/TagTypeDeclaration_Struct.cpp
${PROJECT_SOURCE_DIR}/symbols/TagTypeDeclaration_Struct.h
${PROJECT_SOURCE_DIR}/symbols/TagTypeDeclaration_Union.cpp
${PROJECT_SOURCE_DIR}/symbols/TagTypeDeclaration_Union.h

# Binder
${PROJECT_SOURCE_DIR}/binder/Binder__MACROS__.inc
Expand Down
7 changes: 4 additions & 3 deletions C/Fwds.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,15 @@ typedef SyntaxNodePlainList<ExtKR_ParameterDeclarationSyntax*> ExtKR_ParameterDe
class Symbol;
class Program;
class TranslationUnit;
class DeclarationSymbol;
class Declaration;
class Function;
class ObjectDeclarationSymbol;
class ObjectDeclaration;
class Enumerator;
class Field;
class Variable;
class Parameter;
class TypeDeclarationSymbol;
class TypeDeclaration;
class TagTypeDeclaration;
class Struct;
class Union;
class Enum;
Expand Down
4 changes: 2 additions & 2 deletions C/binder/Binder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ Symbol* Binder::popSymbol()
return sym;
}

DeclarationSymbol* Binder::popSymbolAsDeclaration()
Declaration* Binder::popSymbolAsDeclaration()
{
auto sym = popSymbol();
PSY_ASSERT_2(sym && sym->kind() == SymbolKind::Declaration, return nullptr);
return sym->asDeclarationSymbol();
return sym->asDeclaration();
}

void Binder::pushType(Type* ty)
Expand Down
2 changes: 1 addition & 1 deletion C/binder/Binder.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class PSY_C_INTERNAL_API Binder final : protected SyntaxVisitor
SymContT syms_;
void pushSymbol(Symbol*);
Symbol* popSymbol();
DeclarationSymbol* popSymbolAsDeclaration();
Declaration* popSymbolAsDeclaration();
template <class SymT, class... SymTArgs> SymT* bindAndPushSymbol(
const SyntaxNode* node,
SymTArgs... arg);
Expand Down
47 changes: 26 additions & 21 deletions C/binder/Binder_Declarators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ SyntaxVisitor::Action Binder::visitDeclaration_AtMultipleDeclarators_COMMON(
SYM_AT_TOP(sym);
switch (sym->kind()) {
case SymbolKind::Declaration: {
auto decl = sym->asDeclarationSymbol();
auto decl = sym->asDeclaration();
switch (decl->kind()) {
case DeclarationSymbolKind::Type:
case DeclarationKind::Type:
PSY_ASSERT_1(
decl->asTypeDeclarationSymbol()->kind() == TypeDeclarationSymbolKind::Typedef);
decl->asTypeDeclaration()->kind() == TypeDeclarationKind::Typedef);
[[fallthrough]];

case DeclarationSymbolKind::Function:
case DeclarationSymbolKind::Object: {
case DeclarationKind::Function:
case DeclarationKind::Object: {
typeDeclarationAtTopWithTypeAtTop();
popTypesUntilNonDerivedDeclaratorType();
popSymbol();
Expand Down Expand Up @@ -298,32 +298,37 @@ void Binder::bindObjectOrFunctionAndPushSymbol(const SyntaxNode* node)
SYM_AT_TOP_V(sym);
switch (sym->kind()) {
case SymbolKind::Declaration: {
auto decl = sym->asDeclarationSymbol();
auto decl = sym->asDeclaration();
switch (decl->kind()) {
case DeclarationSymbolKind::Type:
switch (decl->asTypeDeclarationSymbol()->kind()) {
case TypeDeclarationSymbolKind::Union:
case TypeDeclarationSymbolKind::Struct:
bindAndPushSymbol<Field>(node);
case DeclarationKind::Type: {
auto tyDecl = decl->asTypeDeclaration();
switch (tyDecl->kind()) {
case TypeDeclarationKind::Tag: {
auto tagTyDecl = tyDecl->asTagTypeDeclaration();
switch (tagTyDecl->kind()) {
case TagTypeDeclarationKind::Union:
case TagTypeDeclarationKind::Struct:
bindAndPushSymbol<Field>(node);
break;

case TagTypeDeclarationKind::Enum:
bindAndPushSymbol<Enumerator>(node);
break;
}
break;

case TypeDeclarationSymbolKind::Enum:
bindAndPushSymbol<Enumerator>(node);
break;

case TypeDeclarationSymbolKind::Typedef:
}
case TypeDeclarationKind::Typedef:
PSY_ASSERT_2(false, return);
}
break;

case DeclarationSymbolKind::Object:
case DeclarationSymbolKind::Function:
}
case DeclarationKind::Object:
case DeclarationKind::Function:
bindAndPushSymbol<Variable>(node);
break;
}
break;
}

case SymbolKind::TranslationUnit:
bindAndPushSymbol<Variable>(node);
break;
Expand Down
2 changes: 1 addition & 1 deletion C/binder/Binder_End.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ SyntaxVisitor::Action Binder::visitDeclaration_AtEnd_COMMON(const DeclarationSyn
auto decl = popSymbolAsDeclaration();
PSY_ASSERT_2(decl, return Action::Quit);
SCOPE_AT_TOP(scope);
scope->addDeclaration(decl->asDeclarationSymbol());
scope->addDeclaration(decl->asDeclaration());

return Action::Skip;
}
Expand Down
8 changes: 4 additions & 4 deletions C/binder/Scope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ ScopeKind Scope::kind() const
return scopeK_;
}

const DeclarationSymbol* Scope::searchForDeclaration(
const Declaration* Scope::searchForDeclaration(
const Identifier* ident,
NameSpace ns) const
{
Expand All @@ -54,9 +54,9 @@ const DeclarationSymbol* Scope::searchForDeclaration(
: nullptr;
}

std::vector<const DeclarationSymbol*> Scope::declarations() const
std::vector<const Declaration*> Scope::declarations() const
{
std::vector<const DeclarationSymbol*> decls;
std::vector<const Declaration*> decls;
decls.reserve(decls_.size());
std::transform(decls_.begin(),
decls_.end(),
Expand Down Expand Up @@ -94,7 +94,7 @@ void Scope::morphFrom_FunctionPrototype_to_Block()
scopeK_ = ScopeKind::Block;
}

void Scope::addDeclaration(const DeclarationSymbol* decl)
void Scope::addDeclaration(const Declaration* decl)
{
auto key = std::make_pair(decl->identifier(), decl->nameSpace());
auto it = decls_.find(key);
Expand Down
12 changes: 6 additions & 6 deletions C/binder/Scope.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ class PSY_C_API Scope
ScopeKind kind() const;

/**
* Search \c this Scope and \a outer \a scopes of \c this Scope for a DeclarationSymbol with
* Search \c this Scope and \a outer \a scopes of \c this Scope for a Declaration with
* Identifier \p ident in NameSpace \p ns.
*/
const DeclarationSymbol* searchForDeclaration(const Identifier* ident, NameSpace ns) const;
const Declaration* searchForDeclaration(const Identifier* ident, NameSpace ns) const;

/**
* The DeclarationSymbol(s) in \c this Scope.
* The Declaration(s) in \c this Scope.
*/
std::vector<const DeclarationSymbol*> declarations() const;
std::vector<const Declaration*> declarations() const;

/**
* The \a inner \a scopes of \c this Scope.
Expand All @@ -96,15 +96,15 @@ class PSY_C_API Scope

void encloseScope(std::unique_ptr<Scope> innerScope);
void morphFrom_FunctionPrototype_to_Block();
void addDeclaration(const DeclarationSymbol*);
void addDeclaration(const Declaration*);

private:
ScopeKind scopeK_;
Scope* outerScope_;
std::vector<std::unique_ptr<Scope>> innerScopes_;
std::unordered_map<
std::pair<const Identifier*, NameSpace>,
const DeclarationSymbol*> decls_;
const Declaration*> decls_;
};

} // C
Expand Down
12 changes: 6 additions & 6 deletions C/binder/TypeResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ SyntaxVisitor::Action TypeResolver::visitDeclarator_COMMON(const DeclaratorSynta
auto decl = semaModel_->declaredDeclaration(node);
if (decl) {
switch (decl->kind()) {
case DeclarationSymbolKind::Type:
case DeclarationSymbolKind::Function:
case DeclarationSymbolKind::Object: {
case DeclarationKind::Type:
case DeclarationKind::Function:
case DeclarationKind::Object: {
auto typeableDecl = MIXIN_TypeableSymbol::from(decl);
auto ty = typeableDecl->retypeableType();
auto resolvedTy = resolveType(ty, decl->enclosingScope());
Expand Down Expand Up @@ -143,9 +143,9 @@ const Type* TypeResolver::resolveType(const Type* ty, const Scope* scope) const
tydefName,
NameSpace::OrdinaryIdentifiers);
if (decl) {
if (decl->kind() == DeclarationSymbolKind::Type) {
auto tyDecl = decl->asTypeDeclarationSymbol();
PSY_ASSERT_2(tyDecl->kind() == TypeDeclarationSymbolKind::Typedef,
if (decl->kind() == DeclarationKind::Type) {
auto tyDecl = decl->asTypeDeclaration();
PSY_ASSERT_2(tyDecl->kind() == TypeDeclarationKind::Typedef,
return nullptr);
auto tydef = tyDecl->asTypedef();
return tydef->synonymizedType();
Expand Down
Loading

0 comments on commit 427fb23

Please sign in to comment.