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

Const analysis #91

Open
ForNeVeR opened this issue Feb 6, 2022 · 2 comments
Open

Const analysis #91

ForNeVeR opened this issue Feb 6, 2022 · 2 comments
Labels
area:cil-interop Related to CIL (.NET) interop area:compiler Related to code compilation or type checking area:standard-support Related to the C standard support kind:feature New feature or request status:help-wanted Open for contributors

Comments

@ForNeVeR
Copy link
Owner

ForNeVeR commented Feb 6, 2022

As of now, Cesium ignores const keyword almost everywhere.

It should start analyzing const and embed this info into the type (and possibly even into CLI metadata).

See TODO[#91] in the code for possible places where this analysis can be added.

@ForNeVeR ForNeVeR added kind:feature New feature or request status:help-wanted Open for contributors area:cil-interop Related to CIL (.NET) interop area:standard-support Related to the C standard support area:compiler Related to code compilation or type checking labels Feb 6, 2022
@kant2002
Copy link
Collaborator

kant2002 commented Nov 7, 2024

I think we have const in bunch of places. Unless we want to have specific list, we can close this.

@ForNeVeR
Copy link
Owner Author

ForNeVeR commented Nov 7, 2024

I believe that const check should be a part (or a stage, if you will) of the type check algorithm; the problem being we don't have it as a separate entity (yet!).

But you are right in that we should start with some concrete examples. So, let's start with this:

int main() {
    const int *x = 0;
    int *y = x;
    y[0] = 0;
}

This should not compile, yet it happily compiles in Cesium.

A quick unit test, if it helps:

Index: Cesium.CodeGen.Tests/CodeGenArrayTests.cs
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/Cesium.CodeGen.Tests/CodeGenArrayTests.cs b/Cesium.CodeGen.Tests/CodeGenArrayTests.cs
--- a/Cesium.CodeGen.Tests/CodeGenArrayTests.cs	(revision Staged)
+++ b/Cesium.CodeGen.Tests/CodeGenArrayTests.cs	(date 1731013354166)
@@ -14,6 +14,13 @@
         return VerifyMethods(moduleType);
     }
 
+    [Fact]
+    public Task MyCheck1() => DoTest(@"int main() {
+    const int *x = 0;
+    int *y = x;
+    y[0] = 0;
+}");
+
     [Fact]
     public Task ArrayAssignment() => DoTest(@"int main() {
     int a[10];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:cil-interop Related to CIL (.NET) interop area:compiler Related to code compilation or type checking area:standard-support Related to the C standard support kind:feature New feature or request status:help-wanted Open for contributors
Projects
None yet
Development

No branches or pull requests

2 participants