Skip to content

Commit

Permalink
updates, compiler decl attribute so that decls can be checked if they…
Browse files Browse the repository at this point in the history
… are part of compiler
  • Loading branch information
wakaztahir committed Feb 9, 2025
1 parent 6aae223 commit 9d810b7
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 55 deletions.
16 changes: 15 additions & 1 deletion ast/statements/VarInit.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ struct VarInitAttributes {
*/
bool is_comptime;

/**
* compiler declarations are present inside the compiler, no need to import
*/
bool is_compiler_decl;

/**
* has moved is used to indicate that an object at this location has moved
* destructor is not called on moved objects, once moved, any attempt to access
Expand Down Expand Up @@ -88,7 +93,7 @@ class VarInitStatement : public AnnotableNode {
ASTNode* parent_node,
SourceLocation location,
AccessSpecifier specifier = AccessSpecifier::Internal
) : attrs(specifier, false, false, false, is_const, is_reference, false), located_id(identifier), type(type), value(value), parent_node(parent_node), location(location) {
) : attrs(specifier, false, false, false, false, is_const, is_reference, false), located_id(identifier), type(type), value(value), parent_node(parent_node), location(location) {

}

Expand Down Expand Up @@ -136,6 +141,15 @@ class VarInitStatement : public AnnotableNode {
attrs.is_comptime = value;
}

inline bool is_compiler_decl() {
return attrs.is_compiler_decl;
}

inline void set_compiler_decl(bool value) {
attrs.is_comptime = value;
attrs.is_compiler_decl = value;
}

/**
* get the access specifier
*/
Expand Down
18 changes: 16 additions & 2 deletions ast/structures/FunctionDeclaration.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ struct FuncDeclAttributes {
* is this function comptime
*/
bool is_comptime;
/**
* compiler functions are present inside the compiler
* like compiler::println
*/
bool is_compiler_decl;
/**
* when involved in multi function node (due to same name, different parameters)
*/
Expand Down Expand Up @@ -249,7 +254,7 @@ class FunctionDeclaration : public AnnotableNode, public FunctionType {
bool signature_resolved = false
) : FunctionType(std::move(params), returnType, isVariadic, false, parent_node, location, signature_resolved),
identifier(identifier), body(std::move(body)), location(location),
attrs(specifier, false, 0, false, false, false, false, false, false, false, false, false, false) {
attrs(specifier, false, false, 0, false, false, false, false, false, false, false, false, false, false) {
}

/**
Expand All @@ -265,7 +270,7 @@ class FunctionDeclaration : public AnnotableNode, public FunctionType {
bool signature_resolved = false
) : FunctionType(returnType, isVariadic, false, parent_node, location, signature_resolved),
identifier(identifier), location(location),
attrs(specifier, false, 0, false, false, false, false, false, false, false, false, false, false) {
attrs(specifier, false, false, 0, false, false, false, false, false, false, false, false, false, false) {
}

/**
Expand All @@ -287,6 +292,15 @@ class FunctionDeclaration : public AnnotableNode, public FunctionType {
attrs.is_comptime = value;
}

inline bool is_compiler_decl() {
return attrs.is_compiler_decl;
}

inline void set_compiler_decl(bool value) {
attrs.is_comptime = value;
attrs.is_compiler_decl = value;
}

inline void set_specifier_fast(AccessSpecifier specifier) {
attrs.specifier = specifier;
}
Expand Down
9 changes: 0 additions & 9 deletions ast/structures/Namespace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,6 @@
#include "Namespace.h"
#include "compiler/SymbolResolver.h"

Namespace::Namespace(
LocatedIdentifier identifier,
ASTNode* parent_node,
SourceLocation location,
AccessSpecifier specifier
) : identifier(identifier), parent_node(parent_node), location(location), attrs(specifier, false) {

}

void Namespace::declare_node(SymbolResolver& linker, ASTNode* node, const chem::string_view& node_id) {
auto found = extended.find(node_id);
if(found == extended.end()) {
Expand Down
18 changes: 17 additions & 1 deletion ast/structures/Namespace.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ struct NamespaceDeclAttributes {
*/
bool is_comptime;

/**
* compiler declarations are present inside the compiler, no need to import
*/
bool is_compiler_decl;

/**
* is namespace deprecated
*/
Expand Down Expand Up @@ -51,7 +56,9 @@ class Namespace : public AnnotableNode {
ASTNode* parent_node,
SourceLocation location,
AccessSpecifier specifier = AccessSpecifier::Internal
);
) : identifier(identifier), parent_node(parent_node), location(location), attrs(specifier, false, false) {

}

/**
* get the name of node
Expand Down Expand Up @@ -83,6 +90,15 @@ class Namespace : public AnnotableNode {
attrs.is_comptime = value;
}

inline bool is_compiler_decl() {
return attrs.is_compiler_decl;
}

inline void set_compiler_decl(bool value) {
attrs.is_comptime = value;
attrs.is_compiler_decl = value;
}

inline bool deprecated() {
return attrs.deprecated;
}
Expand Down
11 changes: 0 additions & 11 deletions ast/structures/StructDefinition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,17 +347,6 @@ BaseTypeKind StructMember::type_kind() const {
return type->kind();
}

StructDefinition::StructDefinition(
LocatedIdentifier identifier,
ASTNode* parent_node,
SourceLocation location,
AccessSpecifier specifier
) : ExtendableMembersContainerNode(std::move(identifier)), parent_node(parent_node),
location(location), attrs(specifier, false, false, false, false, false, false, false),
linked_type(identifier.identifier, this, location) {

}

//BaseType *StructDefinition::copy(ASTAllocator& allocator) const {
// return new (allocator.allocate<LinkedType>()) LinkedType(name_view(), (ASTNode *) this, location);
//}
Expand Down
20 changes: 19 additions & 1 deletion ast/structures/StructDefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ struct StructDeclAttributes {
*/
bool is_comptime;

/**
* is a compiler declaration (present inside the compiler, no need to import)
*/
bool is_compiler_decl;

/**
* is direct initialization
* constructor or de constructor allow functions to be called automatically
Expand Down Expand Up @@ -90,7 +95,11 @@ class StructDefinition : public ExtendableMembersContainerNode {
ASTNode* parent_node,
SourceLocation location,
AccessSpecifier specifier = AccessSpecifier::Internal
);
) : ExtendableMembersContainerNode(std::move(identifier)), parent_node(parent_node),
location(location), attrs(specifier, false, false, false, false, false, false, false, false),
linked_type(identifier.identifier, this, location) {

}

/**
* get the name of node
Expand Down Expand Up @@ -119,6 +128,15 @@ class StructDefinition : public ExtendableMembersContainerNode {
attrs.is_comptime = value;
}

inline bool is_compiler_decl() {
return attrs.is_compiler_decl;
}

inline void set_compiler_decl(bool value) {
attrs.is_comptime = value;
attrs.is_compiler_decl = value;
}

inline bool is_direct_init() {
return attrs.is_direct_init;
}
Expand Down
Loading

0 comments on commit 9d810b7

Please sign in to comment.