From 60b1ad72f17b600cba84fb60217caa250a492426 Mon Sep 17 00:00:00 2001 From: Raul E Rangel Date: Wed, 9 Jan 2019 11:02:15 -0700 Subject: [PATCH] [C] Allow declaring a struct pointer in a struct Fixes #1830 Signed-off-by: Raul E Rangel --- C++/C.sublime-syntax | 2 +- C++/syntax_test_c.c | 29 ++++++++++++++++++ C++/syntax_test_cpp.cpp | 66 ++++++++++++++++++++++++++++++++++++----- 3 files changed, 88 insertions(+), 9 deletions(-) diff --git a/C++/C.sublime-syntax b/C++/C.sublime-syntax index 0f5385f48be..40aed805783 100644 --- a/C++/C.sublime-syntax +++ b/C++/C.sublime-syntax @@ -451,7 +451,7 @@ contexts: data-structures: # Detect variable type definitions using struct/enum/union followed by a tag - - match: '\b({{before_tag}})(?=\s+{{identifier}}\s+{{identifier}}\s*[=;\[])' + - match: '\b({{before_tag}})(?=\s+{{identifier}}\s+\**\s*{{identifier}}\s*[=;\[])' scope: storage.type.c - match: '\bstruct\b' scope: storage.type.c diff --git a/C++/syntax_test_c.c b/C++/syntax_test_c.c index 838d21b7cb3..6b5d501c71c 100644 --- a/C++/syntax_test_c.c +++ b/C++/syntax_test_c.c @@ -313,6 +313,23 @@ struct foo MACRO { /* ^ - entity.name */ } +struct UI_BoundingBox *position_p; +/* ^ - entity.name */ +/* ^ - entity.name */ + +struct UI_BoundingBox * position_p1; +/* ^ - entity.name */ +/* ^ - entity.name */ + +struct UI_BoundingBox **position_p2; +/* ^ - entity.name */ +/* ^ - entity.name */ + +struct UI_BoundingBox ** position_p3; +/* ^ - entity.name */ +/* ^ - entity.name */ + + // Partially-typed struct foo /* ^ entity.name */ @@ -324,6 +341,18 @@ struct UI_MenuBoxData struct UI_BoundingBox position; /* ^ - entity.name */ /* ^ - entity.name */ + struct UI_BoundingBox *position_p; +/* ^ - entity.name */ +/* ^ - entity.name */ + struct UI_BoundingBox * position_p1; +/* ^ - entity.name */ +/* ^ - entity.name */ + struct UI_BoundingBox **position_p2; +/* ^ - entity.name */ +/* ^ - entity.name */ + struct UI_BoundingBox ** position_p3; +/* ^ - entity.name */ +/* ^ - entity.name */ enum UI_BoxCharType borderType; /* ^ - entity.name */ /* ^ - entity.name */ diff --git a/C++/syntax_test_cpp.cpp b/C++/syntax_test_cpp.cpp index 6a319a1ac35..a86082e8cac 100644 --- a/C++/syntax_test_cpp.cpp +++ b/C++/syntax_test_cpp.cpp @@ -237,6 +237,56 @@ bool foo (bool run=true) {} /* ^ entity.name.function */ }; +struct UI_BoundingBox position; +/* ^ - entity.name */ +/* ^ - entity.name */ + +struct UI_BoundingBox *position_p; +/* ^ - entity.name */ +/* ^ - entity.name */ + +struct UI_BoundingBox * position_p2; +/* ^ - entity.name */ +/* ^ - entity.name */ + +struct UI_BoundingBox **position_p2; +/* ^ - entity.name */ +/* ^ - entity.name */ + +struct UI_BoundingBox ** position_p2; +/* ^ - entity.name */ +/* ^ - entity.name */ + +struct UI_MenuBoxData +/* <- storage.type */ +/* ^ entity.name.struct */ +{ + struct UI_BoundingBox position; +/* ^ - entity.name */ +/* ^ - entity.name */ + struct UI_BoundingBox *position_p; +/* ^ - entity.name */ +/* ^ - entity.name */ + struct UI_BoundingBox * position_p1; +/* ^ - entity.name */ +/* ^ - entity.name */ + struct UI_BoundingBox **position_p2; +/* ^ - entity.name */ +/* ^ - entity.name */ + struct UI_BoundingBox ** position_p3; +/* ^ - entity.name */ +/* ^ - entity.name */ + enum UI_BoxCharType borderType; +/* ^ - entity.name */ +/* ^ - entity.name */ + unsigned int paddingX; + unsigned int paddingY; + struct UI_ScrollBoxText boxContents[]; +/* ^ - entity.name */ +/* ^ - entity.name */ +}; + + ///////////////////////////////////////////// // Strings ///////////////////////////////////////////// @@ -478,7 +528,7 @@ template /* ^ meta.template constant.numeric */ /* ^ meta.template keyword.operator */ /* ^ meta.template constant.language */ -struct Foo +struct Foo { /* <- meta.struct - meta.template */ @@ -515,7 +565,7 @@ template class B { /* ... */ }; /* ^ - meta.template */ template class C { /* ... */ }; -// templates inside templates... it's templates all the way down +// templates inside templates... it's templates all the way down template class P> class X { /* ... */ }; /* ^ meta.template punctuation */ /* ^ meta.template meta.template punctuation */ @@ -615,7 +665,7 @@ int main() { // Example from section 14.2/4 of // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3690.pdf -struct X +struct X { template X* alloc(); @@ -623,12 +673,12 @@ struct X template static X* adjust(); }; -template -void f(T* p) +template +void f(T* p) { // Be optimistic: scope it as a template member function call anyway. T* p1 = p->alloc<200>(); // ill-formed: < means less than - + T* p2 = p->template alloc<200>(); // OK: < starts template argument list /* ^ punctuation.accessor */ /* ^ storage.type - variable.other */ @@ -636,7 +686,7 @@ void f(T* p) // Be optimistic: scope it as a template member function call anyway. T::adjust<100>(); // ill-formed: < means less than - + T::template adjust<100>(); // OK: < starts template argument list /* <- - variable.function */ /*^ punctuation.accessor */ @@ -1783,7 +1833,7 @@ class Foo { /* ^ meta.method.constructor.initializer-list */ /* ^ - meta.function-call - variable.function */ private: - int var1, var2, var3, var4; + int var1, var2, var3, var4; }; class X {