Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide Standard C and C++ Language (without GNU extensions) #184

Closed
wants to merge 25 commits into from

Conversation

TheShermanTanker
Copy link
Contributor

@TheShermanTanker TheShermanTanker commented Nov 29, 2022

WIP - Implement Standard C and C++ as language backends in CDT as an initial experimental step to pave the way for other implementations in the future (MSVC C, etc)

@TheShermanTanker TheShermanTanker marked this pull request as draft November 29, 2022 14:43
@jonahgraham
Copy link
Member

Until you have had a commit merged into CDT I need to manually approve the checks so that they run. Please ping me if I haven't triggered them (or better yet, send me a simple PR I can merge :)

Can you update summary a little as even though this is a draft, it is still visible to everyone.

@github-actions
Copy link

github-actions bot commented Nov 29, 2022

Test Results

0 tests   0 ✔️  0s ⏱️
0 suites  0 💤
0 files    0

Results for commit 7833735.

♻️ This comment has been updated with latest results.

@TheShermanTanker
Copy link
Contributor Author

Can you update summary a little as even though this is a draft, it is still visible to everyone.

It's regarding the conversation we had in #178, specifically:

because no one has contributed a subclass of AbstractCLikeLanguage for MSVC

I think it's probably time that changed ;)

I am, however, trying to add Standard C and C++ in this patch first (without any compiler specific syntax), the reasoning being that Standard C/C++ is likely much easier to implement than a dialect of it, which makes adding it as a language implementation way more useful as a testbed to experiment on how CDT will react to such a change, and work out all the kinks accordingly. I'm fairly certain that once I get this right, doing the same for MSVC C and other forms of C will be a breeze

@jonahgraham jonahgraham changed the title Draft Provide Standard C and C++ Language (without GNU extensions) Nov 30, 2022
@jonahgraham
Copy link
Member

@TheShermanTanker with #225 merged I think that workflows will run automatically for you now that you have a merged PR. If you need to do lots of build & tests in a draft mode I recommend turning on GitHub actions on your fork and add support to the list of branches to build in your fork:

branches: [ "main", "cdt_11_0" ]

@TheShermanTanker TheShermanTanker marked this pull request as ready for review April 19, 2023 10:51
@TheShermanTanker
Copy link
Contributor Author

@jonahgraham I think this might be ready for review now, most of the changes are actually in the new parsers, the rest is just minor code refactoring to other parts of the IDE

Copy link
Member

@jonahgraham jonahgraham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have done a first pass review on this. This is a large change and getting it well reviewed is going to take significant effort. Lets start discussing the initial items I have raised before I do more reviewing.


There is a large section of copied (but modified) code e.g. GNUCPPSourceParser -> CPPSourceParser. I don't think we can support copying that code in the first place as maintaining such forks of that code going forward is unsustainable. And to be able to review it properly we would need to understand why make the changes that were made.


I'm seeing lots of API errors, here is the list in the IDE I see (note that there was another API error that I fixed in #375 so you'll need to rebase to pick them up).

Description	Resource	Path	Location	Type
Missing @since tag on org.eclipse.cdt.core.dom.ast.c.CLanguage	CLanguage.java	/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/c	line 22	@since tag problem
Missing @since tag on org.eclipse.cdt.core.dom.ast.cpp.CPPLanguage	CPPLanguage.java	/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/cpp	line 22	@since tag problem
Missing @since tag on org.eclipse.cdt.core.dom.parser.cpp.CPPScannerExtensionConfiguration	CPPScannerExtensionConfiguration.java	/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/cpp	line 8	@since tag problem
Missing @since tag on org.eclipse.cdt.core.dom.parser.c.CScannerExtensionConfiguration	CScannerExtensionConfiguration.java	/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser/c	line 8	@since tag problem
Invalid @since 5.11 tag on c__HAS_FEATURE; expecting @since 8.2	GCCKeywords.java	/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser	line 48	@since tag problem
Invalid @since 7.1 tag on c__HAS_INCLUDE_NEXT; expecting @since 8.2	GCCKeywords.java	/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser	line 53	@since tag problem
Missing @since tag on cASSERT	GCCKeywords.java	/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser	line 64	@since tag problem
Missing @since tag on cIDENT	GCCKeywords.java	/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser	line 62	@since tag problem
Missing @since tag on cIMPORT	GCCKeywords.java	/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser	line 61	@since tag problem
Missing @since tag on cINCLUDE_NEXT	GCCKeywords.java	/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser	line 60	@since tag problem
Missing @since tag on cpMAX	GCCKeywords.java	/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser	line 57	@since tag problem
Missing @since tag on cpMIN	GCCKeywords.java	/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser	line 56	@since tag problem
Missing @since tag on cSCCS	GCCKeywords.java	/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser	line 63	@since tag problem
Missing @since tag on cUNASSERT	GCCKeywords.java	/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser	line 65	@since tag problem
The field org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_integerPack has been removed	IASTUnaryExpression.java	/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast	line 23	Compatibility Problem
The field org.eclipse.cdt.core.dom.ast.IASTUnaryExpression.op_labelReference has been removed	IASTUnaryExpression.java	/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast	line 23	Compatibility Problem
Missing @since tag on org.eclipse.cdt.core.dom.parser.ICFamilyLanguage	ICFamilyLanguage.java	/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser	line 11	@since tag problem
Missing @since tag on org.eclipse.cdt.core.dom.parser.IExpressionParser	IExpressionParser.java	/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/parser	line 7	@since tag problem
Invalid @since 5.8 tag on op_labelReference; expecting @since 8.2	IGNUASTUnaryExpression.java	/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu	line 27	@since tag problem
Invalid @since 6.11 tag on op_integerPack; expecting @since 8.2	IGNUASTUnaryExpression.java	/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu	line 33	@since tag problem
The field org.eclipse.cdt.core.dom.ast.gnu.IGNUASTUnaryExpression.op_integerPack in an interface that is intended to be implemented or extended has been added	IGNUASTUnaryExpression.java	/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu	line 33	Compatibility Problem
The field org.eclipse.cdt.core.dom.ast.gnu.IGNUASTUnaryExpression.op_labelReference in an interface that is intended to be implemented or extended has been added	IGNUASTUnaryExpression.java	/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/gnu	line 27	Compatibility Problem
The field org.eclipse.cdt.core.parser.Keywords.c__HAS_FEATURE has been removed	Keywords.java	/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser	line 27	Compatibility Problem
The field org.eclipse.cdt.core.parser.Keywords.c__HAS_INCLUDE_NEXT has been removed	Keywords.java	/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser	line 27	Compatibility Problem
The field org.eclipse.cdt.core.parser.Keywords.cASSERT has been removed	Keywords.java	/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser	line 27	Compatibility Problem
The field org.eclipse.cdt.core.parser.Keywords.cIDENT has been removed	Keywords.java	/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser	line 27	Compatibility Problem
The field org.eclipse.cdt.core.parser.Keywords.cIMPORT has been removed	Keywords.java	/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser	line 27	Compatibility Problem
The field org.eclipse.cdt.core.parser.Keywords.cINCLUDE_NEXT has been removed	Keywords.java	/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser	line 27	Compatibility Problem
The field org.eclipse.cdt.core.parser.Keywords.cpMAX has been removed	Keywords.java	/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser	line 27	Compatibility Problem
The field org.eclipse.cdt.core.parser.Keywords.cpMIN has been removed	Keywords.java	/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser	line 27	Compatibility Problem
The field org.eclipse.cdt.core.parser.Keywords.cSCCS has been removed	Keywords.java	/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser	line 27	Compatibility Problem
The field org.eclipse.cdt.core.parser.Keywords.cUNASSERT has been removed	Keywords.java	/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser	line 27	Compatibility Problem
The major version should be incremented in version 8.2.0, since API breakage occurred since version 8.1.1	MANIFEST.MF	/org.eclipse.cdt.core/META-INF	line 5	Version Numbering Problem

Unfortunately you can't remove any API without following the process to remove it. (Moving it is equivalent to removing and adding new API.) This means either waiting two years (assuming that there is no objection) or having a major new version (which is unlikely until late 2024)

* @noreference This interface is not intended to be referenced by clients.
*/
@Deprecated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the deprecation of this interface is unexpected. There is no concrete classes that implement this interface.

@@ -1109,7 +1114,7 @@ private IASTExpression buildExpression(IASTExpression left, BinaryOperator opera
break;
case IToken.tAND:
op = IASTBinaryExpression.op_logicalAnd;
unaryOp = IASTUnaryExpression.op_labelReference;
unaryOp = IGNUASTUnaryExpression.op_labelReference;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment goes with the comment about IGNUASTUnaryExpression not being deprecated anymore.

This leads to a strange case as unaryOp is passed to (eventually) the constructor of one of the concrete classes of IASTUnaryExpression (see call hierarchy of INodeFactory.newUnaryExpression(int, IASTExpression)

I suppose to complete the split there should be a new subclass of org.eclipse.cdt.internal.core.dom.parser.NodeFactory which is GNU vs non-GNU specific.

@jonahgraham
Copy link
Member

There is a large section of copied (but modified) code e.g. GNUCPPSourceParser -> CPPSourceParser. I don't think we can support copying that code in the first place as maintaining such forks of that code going forward is unsustainable. And to be able to review it properly we would need to understand why make the changes that were made.

Have a look at this PR to get a sense of why I don't think there should be two copies of such similar code.

@TheShermanTanker
Copy link
Contributor Author

My apologies, I overlooked that API document for API changes (currently reading the first few bits of your review. I'll need some time to read through all of it).

@TheShermanTanker
Copy link
Contributor Author

Hi @jonahgraham, sorry for such a long period of radio silence, I've been busy with my work on the JDK for a while. I'll start with the easier issues first: What should the copyright headers for the new source files be like? I can't be too sure since the headers in other files are all from companies or institutions, not individual people like myself, I apologize if this is a silly question

@jonahgraham
Copy link
Member

Hi @jonahgraham, sorry for such a long period of radio silence, I've been busy with my work on the JDK for a while.

No worries - and thanks for coming back to this.

I'll start with the easier issues first: What should the copyright headers for the new source files be like? I can't be too sure since the headers in other files are all from companies or institutions, not individual people like myself, I apologize if this is a silly question

If you own the copyright of the code (which is what it sounds like) you should make it your name, e.g.

/*******************************************************************************
 * Copyright (c) 2023 Julian Waters.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 */

If the file is basically copied, make sure to copy the original copyright notice too.

@TheShermanTanker
Copy link
Contributor Author

Alright, I finally had time to do a first pass sweep of all the initial issues raised, hopefully this will fix as many of the API errors as possible

@TheShermanTanker
Copy link
Contributor Author

@jonahgraham How's the API errors looking?

All the duplicated code is pretty much using the established code from the GNU Parsers but modified to remove all the GNU extensions from the parser, developing an entire new parser from scratch seemed like a significant effort when there's already code that can be re-adapted to fit the role of the new ISO language parser. I'm not sure how to approach this issue, unfortunately

@jonahgraham
Copy link
Member

Sorry @TheShermanTanker I have fallen behind again (lost a week+ due to being sick :( ) - I will look again in the coming days.

@TheShermanTanker
Copy link
Contributor Author

Sorry @TheShermanTanker I have fallen behind again (lost a week+ due to being sick :( ) - I will look again in the coming days.

Oh, no worries! Get well soon :)

@jonahgraham
Copy link
Member

@jonahgraham How's the API errors looking?

The API errors are in better shape now. The adding of op_integerPack and op_labelReference to IGNUASTUnaryExpression is technically a breaking change, but I think we'll probably just add a filtered exception for those like this:

diff --git a/core/org.eclipse.cdt.core/.settings/.api_filters b/core/org.eclipse.cdt.core/.settings/.api_filters
index dda81c3a1b..bb58781e77 100644
--- a/core/org.eclipse.cdt.core/.settings/.api_filters
+++ b/core/org.eclipse.cdt.core/.settings/.api_filters
@@ -1,5 +1,19 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <component id="org.eclipse.cdt.core" version="2">
+    <resource path="parser/org/eclipse/cdt/core/dom/ast/gnu/IGNUASTUnaryExpression.java" type="org.eclipse.cdt.core.dom.ast.gnu.IGNUASTUnaryExpression">
+        <filter id="403767336">
+            <message_arguments>
+                <message_argument value="org.eclipse.cdt.core.dom.ast.gnu.IGNUASTUnaryExpression"/>
+                <message_argument value="op_integerPack"/>
+            </message_arguments>
+        </filter>
+        <filter id="403767336">
+            <message_arguments>
+                <message_argument value="org.eclipse.cdt.core.dom.ast.gnu.IGNUASTUnaryExpression"/>
+                <message_argument value="op_labelReference"/>
+            </message_arguments>
+        </filter>
+    </resource>
     <resource path="utils/org/eclipse/cdt/utils/debug/dwarf/DwarfConstants.java" type="org.eclipse.cdt.utils.debug.dwarf.DwarfConstants">
         <filter id="336658481">
             <message_arguments>
-- 
2.40.1

The old names that are left around that you have marked @Deprecated probably want forRemoval set to true. The @Deprecated items also need to have a comment that indicates what consumers of that API should use instead, e.g. on op_labelReference add a comment/link to the new location for this field.

"API removals and API breakages, actual or planned, should be added to New and Noteworthy's API Changelog" - quoted from https://github.com/eclipse-cdt/cdt/blob/main/POLICY.md#deprecating-and-deleting-api


All the duplicated code is pretty much using the established code from the GNU Parsers but modified to remove all the GNU extensions from the parser, developing an entire new parser from scratch seemed like a significant effort when there's already code that can be re-adapted to fit the role of the new ISO language parser. I'm not sure how to approach this issue, unfortunately

I don't want a newly written parser, I just don't think we should copy-paste nearly 3000 lines of code from AbstractGNUSourceCodeParser to AbstractCFamilySourceCodeParser. I imagined that AbstractGNUSourceCodeParser would extend AbstractCFamilySourceCodeParser? Same about CPPSourceParser being copied from GNUCPPSourceParser


I have an additional question - what is the plan for how to deal with things like the modifications made to CPreprocessor? The current PR doesn't error out on the keywords moved to GCCKeywords (AFAICT) when in non-GNU mode. Similar question applies to other places - EvalUnary's changes are another good example.

@TheShermanTanker
Copy link
Contributor Author

Hi Jonah, thanks for getting back to me! :)

Hmm, I had not thought of the utilities like CPreprocessor - I was under the impression that changing the recognized keywords in the XSourceParser classes were enough to change the behaviour. I think we can probably subclass them for the GNU variant instead, and have the original only process C/C++ code without any extensions? Or at least that seems like the best approach to me

I don't want a newly written parser, I just don't think we should copy-paste nearly 3000 lines of code from AbstractGNUSourceCodeParser to AbstractCFamilySourceCodeParser. I imagined that AbstractGNUSourceCodeParser would extend AbstractCFamilySourceCodeParser? Same about CPPSourceParser being copied from GNUCPPSourceParser

Hmm, I can understand AbstractGNUSourceCodeParser extending CFamily one, but if GNUCPPSourceParser extended CPPSourceParser, wouldn't it no longer be an instance/subclass of the AbstractGNUSorceCodeParser?

In any case, I'll deal with the easier fixes first so I can make some progress haha

@jonahgraham
Copy link
Member

but if GNUCPPSourceParser extended CPPSourceParser, wouldn't it no longer be an instance/subclass of the AbstractGNUSorceCodeParser?

Yes - the lack of multiple inheritance in Java may make this refactoring more challenging. Maybe adding additional interfaces would work. I haven't thought through what the full class diagram would look like, maybe it is worth drawing up what the class diagram looks like before refactoring too much? As my understanding is the original purpose of this PR is to make it possible to add an MSVC specialization in the future, including how extenders would fit in probably makes sense.

@jonahgraham
Copy link
Member

I'm going to move this into draft until you are ready to return to this.

@jonahgraham jonahgraham marked this pull request as draft August 18, 2023 17:15
@jonahgraham
Copy link
Member

I am cleaning up our backlog of open Pull Requests. Please re-open this PR if you plan to pick up this work again soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants