Skip to content

Commit 133637c

Browse files
committed
Support for the @group declarator
1 parent 68396b9 commit 133637c

File tree

21 files changed

+332
-25
lines changed

21 files changed

+332
-25
lines changed

README.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
1-
# llvm-logos
1+
# llvm-ObjCS
22

3-
clang-logos is a modified build of apple-llvm, allowing compilation of Logos code directly to LLVM IR.
3+
_Please note that this toolchain is still in very active, early development, and there may be statements or things noted in specifications / this README
4+
that are not yet available or public._
45

5-
The syntax for the logos we compile here is slightly different than DHowett's original Logos syntax.
6+
llvm-ObjCS is a modified build of apple-llvm, allowing compilation of Objective-CS code directly to LLVM IR.
67

7-
Implementing it directly in LLVM as opposed to via a preprocessor allows:
8+
The Objective-CS Language Specification can be viewed here: https://github.com/eswick/Objective-CS
9+
10+
The toolchain has direct integration and companion tooling with the [dragon](https://github.com/DragonBuild/dragon) build system,
11+
and drop-in compatibility with [theos](https://github.com/theos/theos).
12+
13+
It can be used to compile Logos projects, and both Logos and Objective-CS files can be mixed and built within the same project.
14+
15+
---
16+
17+
Implementing it directly in LLVM as opposed to, in logos' case, via a preprocessor allows:
818
* Using @ directives more in line with regular Objective-C
919
* Utilizing clangd / other development tools. Yes, this includes autocomplete/similar features in any editor supporting clangd
1020
* Better error/warning output
1121

12-
13-
1422
And from a development standpoint:
1523
* Far more flexibility, ease of maintenance, from a language standpoint.
1624
* Not having to write/read perl
@@ -21,9 +29,9 @@ I'll update this README.md in the future with better info.
2129

2230
---
2331

24-
This is a modern continuation of Evan Swick's https://github.com/eswick/clang-logos, who has unfortunately since passed away.
32+
This is a modern continuation of Evan Swick's https://github.com/eswick/clang-logos and Objective-CS projects, who has unfortunately since passed away.
2533

26-
Its maintenance has since been continued by cynder
34+
Its maintenance has since been continued by cynder.
2735

2836

2937

clang/include/clang/AST/DeclBase.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class NamedDecl;
5555
class ObjCContainerDecl;
5656
class ObjCMethodDecl;
5757
class ObjCHookDecl;
58+
class ObjCGroupDecl;
5859
struct PrintingPolicy;
5960
class RecordDecl;
6061
class SourceManager;
@@ -1975,6 +1976,7 @@ class DeclContext {
19751976
case Decl::ObjCCategory:
19761977
case Decl::ObjCCategoryImpl:
19771978
case Decl::ObjCHook:
1979+
case Decl::ObjCGroup:
19781980
case Decl::ObjCImplementation:
19791981
case Decl::ObjCInterface:
19801982
case Decl::ObjCProtocol:

clang/include/clang/AST/DeclObjC.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2769,6 +2769,8 @@ class ObjCImplementationDecl : public ObjCImplDecl {
27692769

27702770
raw_ostream &operator<<(raw_ostream &OS, const ObjCImplementationDecl &ID);
27712771

2772+
class ObjCGroupDecl;
2773+
27722774
/// ObjCHookDecl - Represents a class hook definition - this is where
27732775
/// method hooks are specified. For example:
27742776
///
@@ -2780,6 +2782,7 @@ raw_ostream &operator<<(raw_ostream &OS, const ObjCImplementationDecl &ID);
27802782
///
27812783
class ObjCHookDecl : public ObjCImplDecl {
27822784
virtual void anchor();
2785+
ObjCGroupDecl *Group = nullptr;
27832786

27842787
/// MethodDefinitions - map of methods which have been defined in
27852788
/// this hook.
@@ -2804,6 +2807,19 @@ class ObjCHookDecl : public ObjCImplDecl {
28042807
SourceLocation nameLoc,
28052808
SourceLocation atStartLoc);
28062809

2810+
static ObjCHookDecl *Create(ASTContext &C, DeclContext *DC,
2811+
ObjCGroupDecl* group,
2812+
ObjCInterfaceDecl *classInterface,
2813+
SourceLocation nameLoc,
2814+
SourceLocation atStartLoc)
2815+
{
2816+
ObjCHookDecl* hook = Create(C, DC, classInterface, nameLoc, atStartLoc);
2817+
hook->Group = group;
2818+
return hook;
2819+
};
2820+
2821+
ObjCGroupDecl* GetGroup() const { return Group; };
2822+
28072823
void RegisterMethodDefinition(const ObjCMethodDecl *OMD, llvm::Function *Fn);
28082824
llvm::Function *GetMethodDefinition(const ObjCMethodDecl *OMD);
28092825

@@ -2819,6 +2835,27 @@ class ObjCHookDecl : public ObjCImplDecl {
28192835

28202836
};
28212837

2838+
class ObjCGroupDecl : public ObjCContainerDecl {
2839+
2840+
virtual void anchor() override;
2841+
2842+
llvm::DenseSet<ObjCHookDecl*> HookDecls;
2843+
ObjCGroupDecl(DeclContext *DC,
2844+
SourceLocation nameLoc, SourceLocation atStartLoc)
2845+
: ObjCContainerDecl(ObjCGroup, DC, nullptr, nameLoc, atStartLoc) {};
2846+
public:
2847+
static ObjCGroupDecl *Create(ASTContext &C, DeclContext *DC,
2848+
SourceLocation nameLoc,
2849+
SourceLocation atStartLoc);
2850+
2851+
void RegisterHookDecl(ObjCHookDecl* hook);
2852+
llvm::DenseSet<ObjCHookDecl*> GetHookDecls() const { return HookDecls; };
2853+
2854+
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2855+
static bool classofKind(Kind K) { return K == ObjCGroup; }
2856+
2857+
};
2858+
28222859
/// ObjCCompatibleAliasDecl - Represents alias of a class. This alias is
28232860
/// declared as \@compatibility_alias alias class.
28242861
class ObjCCompatibleAliasDecl : public NamedDecl {

clang/include/clang/AST/RecursiveASTVisitor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,6 +1661,9 @@ DEF_TRAVERSE_DECL(ObjCImplementationDecl, {// FIXME: implement
16611661
})
16621662
DEF_TRAVERSE_DECL(ObjCHookDecl, {// FIXME: implement
16631663
})
1664+
DEF_TRAVERSE_DECL(ObjCGroupDecl, {// FIXME: implement
1665+
})
1666+
16641667

16651668
DEF_TRAVERSE_DECL(ObjCInterfaceDecl, {
16661669
if (ObjCTypeParamList *typeParamList = D->getTypeParamListAsWritten()) {

clang/include/clang/Basic/DeclNodes.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def Named : DeclNode<Decl, "named declarations", 1>;
8484
def ObjCCategory : DeclNode<ObjCContainer>;
8585
def ObjCProtocol : DeclNode<ObjCContainer, "Objective-C protocols">;
8686
def ObjCInterface : DeclNode<ObjCContainer, "Objective-C interfaces">;
87+
def ObjCGroup : DeclNode<ObjCContainer, "Objective-C Group">;
8788
def ObjCImpl
8889
: DeclNode<ObjCContainer, "Objective-C implementation declarations", 1>;
8990
def ObjCCategoryImpl : DeclNode<ObjCImpl>;

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ def err_expected_minus_or_plus : Error<
472472
def err_objc_missing_end : Error<"missing '@end'">;
473473
def note_objc_container_start : Note<
474474
"%select{class|protocol|category|class extension|implementation"
475-
"|category implementation|hook}0 started here">;
475+
"|category implementation|hook|group}0 started here">;
476476
def warn_objc_protocol_qualifier_missing_id : Warning<
477477
"protocol has no object type specified; defaults to qualified 'id'">;
478478
def err_objc_unknown_at : Error<"expected an Objective-C directive after '@'">;

clang/include/clang/Basic/TokenKinds.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,7 @@ OBJC_AT_KEYWORD(import)
792792
OBJC_AT_KEYWORD(available)
793793

794794
OBJC_AT_KEYWORD(hook)
795+
OBJC_AT_KEYWORD(group)
795796
OBJC_AT_KEYWORD(orig)
796797
OBJC_AT_KEYWORD(new)
797798

clang/include/clang/Index/USRGeneration.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,13 @@ bool generateUSRForDecl(const Decl *D, SmallVectorImpl<char> &Buf);
3333

3434
/// Generate a USR fragment for an Objective-C hook.
3535
void generateUSRForObjCHook(StringRef Cls, raw_ostream &OS,
36-
StringRef ExtSymbolDefinedIn = "",
37-
StringRef CategoryContextExtSymbolDefinedIn = "");
36+
StringRef ExtSymbolDefinedIn = "",
37+
StringRef CategoryContextExtSymbolDefinedIn = "");
38+
39+
/// Generate a USR fragment for an Objective-C group.
40+
void generateUSRForObjCGroup(StringRef Cls, raw_ostream &OS,
41+
StringRef ExtSymbolDefinedIn = "",
42+
StringRef CategoryContextExtSymbolDefinedIn = "");
3843

3944
/// Generate a USR fragment for an Objective-C class.
4045
void generateUSRForObjCClass(StringRef Cls, raw_ostream &OS,

clang/include/clang/Parse/Parser.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,15 +1722,35 @@ class Parser : public CodeCompletionHandler {
17221722
void finish(SourceRange AtEnd);
17231723
bool isFinished() const { return Finished; }
17241724

1725+
private:
1726+
bool Finished;
1727+
};
1728+
1729+
struct ObjCGroupParsingDataRAII {
1730+
Parser &P;
1731+
Decl *Dcl;
1732+
1733+
ObjCGroupParsingDataRAII(Parser &parser, Decl *D)
1734+
: P(parser), Dcl(D) {
1735+
P.CurParsedObjCGroup = this;
1736+
Finished = false;
1737+
}
1738+
~ObjCGroupParsingDataRAII();
1739+
1740+
void finish(SourceRange AtEnd);
1741+
bool isFinished() const { return Finished; }
1742+
17251743
private:
17261744
bool Finished;
17271745
};
17281746
ObjCImplParsingDataRAII *CurParsedObjCImpl;
1747+
ObjCGroupParsingDataRAII *CurParsedObjCGroup = nullptr;
17291748
void StashAwayMethodOrFunctionBodyTokens(Decl *MDecl);
17301749

17311750
DeclGroupPtrTy ParseObjCAtImplementationDeclaration(SourceLocation AtLoc,
17321751
ParsedAttributes &Attrs);
17331752
DeclGroupPtrTy ParseObjCAtHookDeclaration(SourceLocation AtLoc);
1753+
DeclGroupPtrTy ParseObjCAtGroupDeclaration(SourceLocation AtLoc);
17341754
DeclGroupPtrTy ParseObjCAtEndDeclaration(SourceRange atEnd);
17351755
Decl *ParseObjCAtAliasDeclaration(SourceLocation atLoc);
17361756
Decl *ParseObjCPropertySynthesize(SourceLocation atLoc);

clang/include/clang/Sema/Sema.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10255,7 +10255,8 @@ class Sema final {
1025510255
OCK_ClassExtension,
1025610256
OCK_Implementation,
1025710257
OCK_CategoryImplementation,
10258-
OCK_Hook
10258+
OCK_Hook,
10259+
OCK_Group
1025910260
};
1026010261
ObjCContainerKind getObjCContainerKind() const;
1026110262

@@ -10333,6 +10334,8 @@ class Sema final {
1033310334
const ParsedAttributesView &AttrList);
1033410335

1033510336
Decl *ActOnStartHook(SourceLocation AtHookLoc,
10337+
IdentifierInfo *ClassName, SourceLocation ClassLoc, ObjCGroupDecl* Group = nullptr);
10338+
Decl *ActOnStartGroup(SourceLocation AtHookLoc,
1033610339
IdentifierInfo *ClassName, SourceLocation ClassLoc);
1033710340
DeclGroupPtrTy ActOnFinishObjCImplementation(Decl *ObjCImpDecl,
1033810341
ArrayRef<Decl *> Decls);

0 commit comments

Comments
 (0)