Skip to content

Commit

Permalink
Created a minimal example to show related problems
Browse files Browse the repository at this point in the history
It shows that user generated names are not currently prevented from
shadowing previously declared variables, whether they were generated by
GOOL or previously declared by the user.
  • Loading branch information
B-rando1 committed Jul 22, 2024
1 parent 8803ca5 commit 5b8e1cd
Show file tree
Hide file tree
Showing 15 changed files with 273 additions and 2 deletions.
1 change: 1 addition & 0 deletions code/drasil-code/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ executables:
- PatternTest
- VectorTest
- NameGenTest
- NameGenExample
ghc-options:
- -threaded
- -O2
Expand Down
5 changes: 3 additions & 2 deletions code/drasil-code/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import PatternTest (patternTest)
import FileTests (fileTests)
import VectorTest (vectorTest)
import NameGenTest (nameGenTest)
import NameGenExample (nameGenExample)

-- | Renders five GOOL tests (FileTests, HelloWorld, PatternTest, VectorTest, and NameGenTest)
-- in Java, Python, C#, C++, and Swift.
Expand Down Expand Up @@ -60,8 +61,8 @@ classes unRepr unRepr' = zipWith
(\p gs -> let (p',gs') = runState p gs
pd = unRepr p'
in unRepr' $ package pd [makefile [] Program [] gs' pd])
[helloWorld, patternTest, fileTests, vectorTest, nameGenTest]
(map (unCI . (`evalState` initialState)) [helloWorld, patternTest, fileTests, vectorTest, nameGenTest])
[helloWorld, patternTest, fileTests, vectorTest, nameGenTest, nameGenExample]
(map (unCI . (`evalState` initialState)) [helloWorld, patternTest, fileTests, vectorTest, nameGenTest, nameGenExample])

-- | Formats code to be rendered.
makeCode :: [[FileData]] -> [[AuxData]] -> [(FilePath, Doc)]
Expand Down
29 changes: 29 additions & 0 deletions code/drasil-code/test/NameGenExample.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module NameGenExample (nameGenExample) where

import Drasil.GOOL

nameGenExample :: OOProg r => GSProgram r
nameGenExample = prog "NameGenExample" "" [fileDoc $ buildModule "NameGenExample" [] [main, helper] []]

helper :: OOProg r => SMethod r
helper = function "helper" private void [param temp] $ body
[block [listDec 2 result],
listSlice result (valueOf temp) (Just (litInt 1)) (Just (litInt 3)) Nothing]
where
temp = var "temp" (listType int) local
result = var "result" (listType int) local

main :: OOProg r => SMethod r
main = mainFunction $ body
[block [listDecDef temp [litInt 1, litInt 2, litInt 3],
listDec 2 result],
listSlice result (valueOf temp) (Just (litInt 1)) (Just (litInt 3)) Nothing,
block [
comment "This shadows a generated name:",
listDecDef temp0 [litInt 1, litInt 2, litInt 3],
comment "This shadows a user-given name:",
listDec 2 result]]
where
temp = mainVar "temp" (listType int)
result = mainVar "result" (listType int)
temp0 = mainVar "temp0" (listType int)
3 changes: 3 additions & 0 deletions code/hie.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ cradle:
- path: "drasil-code/test/NameGenTest.hs"
component: "drasil-code:exe:codegenTest"

- path: "drasil-code/test/NameGenExample.hs"
component: "drasil-code:exe:codegenTest"

- path: "drasil-codeLang/lib"
component: "drasil-codeLang:lib"

Expand Down
25 changes: 25 additions & 0 deletions code/stable/gooltest/cpp/NameGenExample/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions code/stable/gooltest/cpp/NameGenExample/NameGenExample.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions code/stable/gooltest/cpp/NameGenExample/NameGenExample.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions code/stable/gooltest/csharp/NameGenExample/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions code/stable/gooltest/csharp/NameGenExample/NameGenExample.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions code/stable/gooltest/java/NameGenExample/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions code/stable/gooltest/python/NameGenExample/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions code/stable/gooltest/python/NameGenExample/NameGenExample.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions code/stable/gooltest/swift/NameGenExample/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions code/stable/gooltest/swift/NameGenExample/main.swift

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5b8e1cd

Please sign in to comment.