Guest User

Untitled

a guest
Apr 24th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. diff --git a/src/org/ooc/backend/cdirty/VariableDeclWriter.java b/src/org/ooc/backend/cdirty/VariableDeclWriter.java
  2. index e3034f2..fa5208e 100644
  3. --- a/src/org/ooc/backend/cdirty/VariableDeclWriter.java
  4. +++ b/src/org/ooc/backend/cdirty/VariableDeclWriter.java
  5. @@ -15,6 +15,26 @@ public class VariableDeclWriter {
  6.  
  7. if(variableDecl.isExtern()) return false;
  8.  
  9. + if (variableDecl.isGlobal())
  10. + {
  11. + assert cgen.current == cgen.hw;
  12. + cgen.current.app("extern ");
  13. + writeGuts(variableDecl, cgen);
  14. + cgen.current = cgen.cw;
  15. + writeGuts(variableDecl, cgen);
  16. + cgen.current.app(";\n");
  17. + cgen.current = cgen.hw;
  18. + }
  19. + else
  20. + {
  21. + writeGuts(variableDecl, cgen);
  22. + }
  23. +
  24. + return true;
  25. +
  26. + }
  27. +
  28. + private static void writeGuts(VariableDecl variableDecl, CGenerator cgen) throws IOException {
  29. // FIXME add const checking from the ooc side of things. Disabled C's
  30. // const keyword because it causes problems with class initializations
  31. //if(variableDecl.isConst()) cgen.current.app("const ");
  32. @@ -61,9 +81,6 @@ public class VariableDeclWriter {
  33. }
  34.  
  35. }
  36. -
  37. - return true;
  38. -
  39. }
  40.  
  41. private static void writeInitAndComma(CGenerator cgen, Type type,
  42. diff --git a/src/org/ooc/frontend/model/VariableDecl.java b/src/org/ooc/frontend/model/VariableDecl.java
  43. index 4be4505..35e39eb 100644
  44. --- a/src/org/ooc/frontend/model/VariableDecl.java
  45. +++ b/src/org/ooc/frontend/model/VariableDecl.java
  46. @@ -68,6 +68,7 @@ public class VariableDecl extends Declaration implements MustBeUnwrapped, Potent
  47. }
  48.  
  49. private boolean isStatic;
  50. + private boolean isGlobal;
  51.  
  52. protected Type type;
  53. protected TypeDecl typeDecl;
  54. @@ -146,6 +147,14 @@ public class VariableDecl extends Declaration implements MustBeUnwrapped, Potent
  55. this.isStatic = isStatic;
  56. }
  57.  
  58. + public boolean isGlobal() {
  59. + return isGlobal;
  60. + }
  61. +
  62. + public void setGlobal(boolean isGlobal) {
  63. + this.isGlobal = isGlobal;
  64. + }
  65. +
  66. public void accept(Visitor visitor) throws IOException {
  67. visitor.visit(this);
  68. }
  69. diff --git a/src/org/ooc/frontend/parser/ModuleParser.java b/src/org/ooc/frontend/parser/ModuleParser.java
  70. index e8f9d4a..aa21312 100644
  71. --- a/src/org/ooc/frontend/parser/ModuleParser.java
  72. +++ b/src/org/ooc/frontend/parser/ModuleParser.java
  73. @@ -70,6 +70,7 @@ public class ModuleParser {
  74. if(declaration != null) {
  75. if(declaration instanceof VariableDecl) {
  76. module.getBody().add(new Line(declaration));
  77. + ((VariableDecl)declaration).setGlobal(true);
  78. } else {
  79. module.getBody().add(declaration);
  80. }
Add Comment
Please, Sign In to add comment