Bläddra i källkod

Simplified dependencies and the build tree with some minor refactoring.

Stan Hebben 6 år sedan
förälder
incheckning
3094e93529
30 ändrade filer med 85 tillägg och 94 borttagningar
  1. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/ModuleSpace.java
  2. 2
    35
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/SemanticModule.java
  3. 2
    0
      CompilerShared/src/main/java/org/openzen/zenscript/compiler/ModuleReference.java
  4. 1
    0
      CompilerShared/src/main/java/org/openzen/zenscript/compiler/ModuleRegistry.java
  5. 2
    0
      CompilerShared/src/main/java/org/openzen/zenscript/compiler/Target.java
  6. 2
    0
      CompilerShared/src/main/java/org/openzen/zenscript/compiler/ZenCodeCompiler.java
  7. 1
    1
      Constructor/src/main/java/org/openzen/zenscript/constructor/ConstructorRegistry.java
  8. 1
    1
      Constructor/src/main/java/org/openzen/zenscript/constructor/ModuleLoader.java
  9. 2
    2
      Constructor/src/main/java/org/openzen/zenscript/constructor/module/DirectoryModuleReference.java
  10. 1
    1
      Constructor/src/main/java/org/openzen/zenscript/constructor/module/ModuleReference.java
  11. 3
    2
      IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalModule.java
  12. 8
    10
      IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalTarget.java
  13. 1
    7
      JavaAnnotations/build.gradle
  14. 0
    1
      JavaBytecodeCompiler/build.gradle
  15. 1
    1
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaCompiler.java
  16. 1
    1
      JavaIntegration/build.gradle
  17. 2
    2
      JavaIntegration/src/main/java/org/openzen/zencode/java/JavaNativeModule.java
  18. 11
    10
      JavaIntegration/src/main/java/org/openzen/zencode/java/ScriptingEngine.java
  19. 0
    1
      JavaShared/build.gradle
  20. 1
    4
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaBaseCompiler.java
  21. 1
    1
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaDefinitionVisitor.java
  22. 1
    1
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaMemberCompiler.java
  23. 1
    1
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceCompiler.java
  24. 1
    1
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceFile.java
  25. 0
    1
      Parser/build.gradle
  26. 2
    2
      Parser/src/main/java/org/openzen/zenscript/parser/ParsedFile.java
  27. 2
    2
      Parser/src/main/java/org/openzen/zenscript/parser/ZippedPackage.java
  28. 0
    4
      ScriptingExample/build.gradle
  29. 1
    1
      ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/Main.java
  30. 33
    0
      Validator/src/main/java/org/openzen/zenscript/validator/Validator.java

CompilerShared/src/main/java/org/openzen/zenscript/compiler/ModuleSpace.java → CodeModel/src/main/java/org/openzen/zenscript/codemodel/ModuleSpace.java Visa fil

@@ -3,7 +3,7 @@
3 3
  * To change this template file, choose Tools | Templates
4 4
  * and open the template in the editor.
5 5
  */
6
-package org.openzen.zenscript.compiler;
6
+package org.openzen.zenscript.codemodel;
7 7
 
8 8
 import java.util.ArrayList;
9 9
 import java.util.HashMap;

CompilerShared/src/main/java/org/openzen/zenscript/compiler/SemanticModule.java → CodeModel/src/main/java/org/openzen/zenscript/codemodel/SemanticModule.java Visa fil

@@ -3,18 +3,13 @@
3 3
  * To change this template file, choose Tools | Templates
4 4
  * and open the template in the editor.
5 5
  */
6
-package org.openzen.zenscript.compiler;
6
+package org.openzen.zenscript.codemodel;
7 7
 
8 8
 import java.util.ArrayList;
9 9
 import java.util.HashMap;
10 10
 import java.util.List;
11 11
 import java.util.Map;
12
-import java.util.function.Consumer;
13 12
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
14
-import org.openzen.zenscript.codemodel.HighLevelDefinition;
15
-import org.openzen.zenscript.codemodel.Module;
16
-import org.openzen.zenscript.codemodel.PackageDefinitions;
17
-import org.openzen.zenscript.codemodel.ScriptBlock;
18 13
 import org.openzen.zenscript.codemodel.annotations.AnnotationProcessor;
19 14
 import org.openzen.zenscript.codemodel.context.ModuleContext;
20 15
 import org.openzen.zenscript.codemodel.context.ModuleTypeResolutionContext;
@@ -24,8 +19,6 @@ import org.openzen.zenscript.codemodel.scope.FileScope;
24 19
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
25 20
 import org.openzen.zenscript.codemodel.type.ISymbol;
26 21
 import org.openzen.zenscript.codemodel.type.storage.StorageType;
27
-import org.openzen.zenscript.validator.ValidationLogEntry;
28
-import org.openzen.zenscript.validator.Validator;
29 22
 
30 23
 /**
31 24
  *
@@ -37,7 +30,7 @@ public class SemanticModule {
37 30
 	public final String name;
38 31
 	public final SemanticModule[] dependencies;
39 32
 	
40
-	private State state;
33
+	public final State state;
41 34
 	public final Module module;
42 35
 	public final ZSPackage rootPackage;
43 36
 	public final ZSPackage modulePackage;
@@ -114,32 +107,6 @@ public class SemanticModule {
114 107
 				storageTypes);
115 108
 	}
116 109
 	
117
-	public boolean validate(Consumer<ValidationLogEntry> logger) {
118
-		if (state != State.NORMALIZED)
119
-			throw new IllegalStateException("Module is not yet normalized");
120
-		
121
-		Validator validator = new Validator(registry, expansions, annotations);
122
-		for (ScriptBlock script : scripts) {
123
-			validator.validate(script);
124
-		}
125
-		for (HighLevelDefinition definition : definitions.getAll()) {
126
-			validator.validate(definition);
127
-		}
128
-		
129
-		for (ValidationLogEntry entry : validator.getLog()) {
130
-			logger.accept(entry);
131
-		}
132
-		state = validator.hasErrors() ? State.INVALID : State.VALIDATED;
133
-		return !validator.hasErrors();
134
-	}
135
-	
136
-	public void compile(ZenCodeCompiler compiler) {
137
-		if (state != State.VALIDATED)
138
-			throw new IllegalStateException("Module is not yet validated");
139
-		
140
-		compiler.addModule(this);
141
-	}
142
-	
143 110
 	public ModuleContext getContext() {
144 111
 		return new ModuleContext(registry, module, expansions, rootPackage);
145 112
 	}

+ 2
- 0
CompilerShared/src/main/java/org/openzen/zenscript/compiler/ModuleReference.java Visa fil

@@ -5,6 +5,8 @@
5 5
  */
6 6
 package org.openzen.zenscript.compiler;
7 7
 
8
+import org.openzen.zenscript.codemodel.SemanticModule;
9
+
8 10
 /**
9 11
  *
10 12
  * @author Hoofdgebruiker

+ 1
- 0
CompilerShared/src/main/java/org/openzen/zenscript/compiler/ModuleRegistry.java Visa fil

@@ -13,6 +13,7 @@ import java.util.Stack;
13 13
 import org.openzen.zencode.shared.CodePosition;
14 14
 import org.openzen.zencode.shared.CompileException;
15 15
 import org.openzen.zencode.shared.CompileExceptionCode;
16
+import org.openzen.zenscript.codemodel.SemanticModule;
16 17
 
17 18
 /**
18 19
  *

+ 2
- 0
CompilerShared/src/main/java/org/openzen/zenscript/compiler/Target.java Visa fil

@@ -5,6 +5,8 @@
5 5
  */
6 6
 package org.openzen.zenscript.compiler;
7 7
 
8
+import org.openzen.zenscript.codemodel.SemanticModule;
9
+
8 10
 /**
9 11
  *
10 12
  * @author Hoofdgebruiker

+ 2
- 0
CompilerShared/src/main/java/org/openzen/zenscript/compiler/ZenCodeCompiler.java Visa fil

@@ -5,6 +5,8 @@
5 5
  */
6 6
 package org.openzen.zenscript.compiler;
7 7
 
8
+import org.openzen.zenscript.codemodel.SemanticModule;
9
+
8 10
 /**
9 11
  *
10 12
  * @author Hoofdgebruiker

+ 1
- 1
Constructor/src/main/java/org/openzen/zenscript/constructor/ConstructorRegistry.java Visa fil

@@ -11,9 +11,9 @@ import java.util.HashMap;
11 11
 import java.util.List;
12 12
 import java.util.Map;
13 13
 import org.json.JSONObject;
14
+import org.openzen.zenscript.codemodel.SemanticModule;
14 15
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
15 16
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
16
-import org.openzen.zenscript.compiler.SemanticModule;
17 17
 import org.openzen.zenscript.compiler.Target;
18 18
 import org.openzen.zenscript.compiler.TargetType;
19 19
 import org.openzen.zenscript.compiler.ZenCodeCompiler;

+ 1
- 1
Constructor/src/main/java/org/openzen/zenscript/constructor/ModuleLoader.java Visa fil

@@ -11,9 +11,9 @@ import java.util.Map;
11 11
 import java.util.Stack;
12 12
 import java.util.function.Consumer;
13 13
 import org.openzen.zencode.shared.CompileException;
14
+import org.openzen.zenscript.codemodel.SemanticModule;
14 15
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
15 16
 import org.openzen.zenscript.constructor.module.ModuleReference;
16
-import org.openzen.zenscript.compiler.SemanticModule;
17 17
 
18 18
 /**
19 19
  *

+ 2
- 2
Constructor/src/main/java/org/openzen/zenscript/constructor/module/DirectoryModuleReference.java Visa fil

@@ -5,8 +5,6 @@
5 5
  */
6 6
 package org.openzen.zenscript.constructor.module;
7 7
 
8
-import org.openzen.zenscript.compiler.ModuleSpace;
9
-import org.openzen.zenscript.compiler.SemanticModule;
10 8
 import java.io.File;
11 9
 import java.io.IOException;
12 10
 import java.util.ArrayList;
@@ -17,6 +15,8 @@ import org.json.JSONObject;
17 15
 import org.openzen.zencode.shared.CompileException;
18 16
 import org.openzen.zencode.shared.FileSourceFile;
19 17
 import org.openzen.zenscript.codemodel.Module;
18
+import org.openzen.zenscript.codemodel.ModuleSpace;
19
+import org.openzen.zenscript.codemodel.SemanticModule;
20 20
 import org.openzen.zenscript.codemodel.context.CompilingPackage;
21 21
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
22 22
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;

+ 1
- 1
Constructor/src/main/java/org/openzen/zenscript/constructor/module/ModuleReference.java Visa fil

@@ -7,8 +7,8 @@ package org.openzen.zenscript.constructor.module;
7 7
 
8 8
 import java.util.function.Consumer;
9 9
 import org.openzen.zencode.shared.CompileException;
10
+import org.openzen.zenscript.codemodel.SemanticModule;
10 11
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
11
-import org.openzen.zenscript.compiler.SemanticModule;
12 12
 import org.openzen.zenscript.constructor.ModuleLoader;
13 13
 
14 14
 /**

+ 3
- 2
IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalModule.java Visa fil

@@ -6,12 +6,13 @@
6 6
 package org.openzen.zenscript.ide.host.local;
7 7
 
8 8
 import java.util.function.Consumer;
9
-import org.openzen.zenscript.compiler.SemanticModule;
9
+import org.openzen.zenscript.codemodel.SemanticModule;
10 10
 import org.openzen.zenscript.constructor.ModuleLoader;
11 11
 import org.openzen.zenscript.constructor.module.ModuleReference;
12 12
 import org.openzen.zenscript.ide.codemodel.IDECodeError;
13 13
 import org.openzen.zenscript.ide.host.IDEModule;
14 14
 import org.openzen.zenscript.ide.host.IDEPackage;
15
+import org.openzen.zenscript.validator.Validator;
15 16
 
16 17
 /**
17 18
  *
@@ -39,6 +40,6 @@ public class LocalModule implements IDEModule {
39 40
 	@Override
40 41
 	public void prebuild(ModuleLoader loader, Consumer<IDECodeError> errors) {
41 42
 		SemanticModule module = loader.getModule(this.module.getName());
42
-		module.validate(entry -> errors.accept(new IDECodeError(null, entry.position, entry.message)));
43
+		Validator.validate(module, entry -> errors.accept(new IDECodeError(null, entry.position, entry.message)));
43 44
 	}
44 45
 }

+ 8
- 10
IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalTarget.java Visa fil

@@ -10,6 +10,7 @@ import java.util.HashSet;
10 10
 import java.util.Set;
11 11
 import java.util.Stack;
12 12
 import java.util.function.Consumer;
13
+import org.openzen.zenscript.codemodel.SemanticModule;
13 14
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
14 15
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
15 16
 import org.openzen.zenscript.compiler.Target;
@@ -19,11 +20,11 @@ import org.openzen.zenscript.constructor.ModuleLoader;
19 20
 import org.openzen.zenscript.constructor.Project;
20 21
 import org.openzen.zenscript.constructor.module.DirectoryModuleReference;
21 22
 import org.openzen.zenscript.constructor.module.ModuleReference;
22
-import org.openzen.zenscript.compiler.SemanticModule;
23 23
 import org.openzen.zenscript.ide.host.IDETarget;
24 24
 import org.openzen.zenscript.ide.ui.view.output.ErrorOutputSpan;
25 25
 import org.openzen.zenscript.ide.ui.view.output.OutputLine;
26 26
 import org.openzen.zenscript.validator.ValidationLogEntry;
27
+import org.openzen.zenscript.validator.Validator;
27 28
 import stdlib.Strings;
28 29
 
29 30
 /**
@@ -96,27 +97,25 @@ public class LocalTarget implements IDETarget {
96 97
 			}
97 98
 			
98 99
 			SemanticModule module = moduleLoader.getModule(target.getModule());
99
-			module = module.normalize();
100
-			module.validate(validationLogger);
100
+			module = Validator.validate(module.normalize(), validationLogger);
101 101
 			
102 102
 			ZenCodeCompiler compiler = target.createCompiler(module);
103 103
 			if (!module.isValid())
104 104
 				return compiler;
105 105
 			
106 106
 			SemanticModule stdlib = moduleLoader.getModule("stdlib");
107
-			stdlib = stdlib.normalize();
108
-			stdlib.validate(validationLogger);
107
+			stdlib = Validator.validate(stdlib.normalize(), validationLogger);
109 108
 			if (!stdlib.isValid())
110 109
 				return compiler;
111 110
 			
112
-			stdlib.compile(compiler);
111
+			compiler.addModule(stdlib);
113 112
 			compiledModules.add(stdlib.name);
114 113
 			
115 114
 			boolean isValid = compileDependencies(moduleLoader, compiler, compiledModules, new Stack<>(), module, validationLogger);
116 115
 			if (!isValid)
117 116
 				return compiler;
118 117
 			
119
-			module.compile(compiler);
118
+			compiler.addModule(module);
120 119
 			compiler.finish();
121 120
 			return compiler;
122 121
 		} catch (Exception ex) {
@@ -159,8 +158,7 @@ public class LocalTarget implements IDETarget {
159 158
 				return false;
160 159
 			}
161 160
 			
162
-			dependency = dependency.normalize();
163
-			dependency.validate(logger);
161
+			dependency = Validator.validate(dependency.normalize(), logger);
164 162
 			if (!dependency.isValid()) {
165 163
 				compilingModules.pop();
166 164
 				return false;
@@ -171,7 +169,7 @@ public class LocalTarget implements IDETarget {
171 169
 				return false;
172 170
 			}
173 171
 			
174
-			dependency.compile(compiler);
172
+			compiler.addModule(dependency);
175 173
 			compilingModules.pop();
176 174
 		}
177 175
 		

+ 1
- 7
JavaAnnotations/build.gradle Visa fil

@@ -14,11 +14,5 @@ if (!hasProperty('mainClass')) {
14 14
 }
15 15
 
16 16
 dependencies {
17
-    // TODO: Add dependencies here
18
-    //   but note that JUnit should have already been added in parent.gradle.
19
-    //   By default, only the Maven Central Repository is specified in
20
-    //   parent.gradle.
21
-    //
22
-    // You can read more about how to add dependency here:
23
-    //   http://www.gradle.org/docs/current/userguide/dependency_management.html#sec:how_to_declare_your_dependencies
17
+    // no dependencies
24 18
 }

+ 0
- 1
JavaBytecodeCompiler/build.gradle Visa fil

@@ -16,6 +16,5 @@ if (!hasProperty('mainClass')) {
16 16
 dependencies {
17 17
 	compile 'org.ow2.asm:asm-debug-all:6.0_BETA'
18 18
 	compile project(':CodeModel')
19
-	compile project(':CompilerShared')
20 19
 	compile project(':JavaShared')
21 20
 }

+ 1
- 1
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaCompiler.java Visa fil

@@ -12,9 +12,9 @@ import org.objectweb.asm.Opcodes;
12 12
 import org.openzen.zencode.shared.SourceFile;
13 13
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
14 14
 import org.openzen.zenscript.codemodel.ScriptBlock;
15
+import org.openzen.zenscript.codemodel.SemanticModule;
15 16
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
16 17
 import org.openzen.zenscript.codemodel.statement.Statement;
17
-import org.openzen.zenscript.compiler.SemanticModule;
18 18
 import org.openzen.zenscript.javabytecode.compiler.JavaClassWriter;
19 19
 import org.openzen.zenscript.javabytecode.compiler.JavaScriptFile;
20 20
 import org.openzen.zenscript.javabytecode.compiler.JavaStatementVisitor;

+ 1
- 1
JavaIntegration/build.gradle Visa fil

@@ -15,8 +15,8 @@ if (!hasProperty('mainClass')) {
15 15
 
16 16
 dependencies {
17 17
 	compile project(':CodeModel')
18
-	compile project(':CompilerShared')
19 18
 	compile project(':Parser')
20 19
 	compile project(':JavaBytecodeCompiler')
21 20
 	compile project(':JavaAnnotations')
21
+	compile project(':Validator')
22 22
 }

+ 2
- 2
JavaIntegration/src/main/java/org/openzen/zencode/java/JavaNativeModule.java Visa fil

@@ -22,8 +22,10 @@ import org.openzen.zenscript.codemodel.GenericMapper;
22 22
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
23 23
 import org.openzen.zenscript.codemodel.Modifiers;
24 24
 import org.openzen.zenscript.codemodel.Module;
25
+import org.openzen.zenscript.codemodel.ModuleSpace;
25 26
 import org.openzen.zenscript.codemodel.OperatorType;
26 27
 import org.openzen.zenscript.codemodel.PackageDefinitions;
28
+import org.openzen.zenscript.codemodel.SemanticModule;
27 29
 import org.openzen.zenscript.codemodel.definition.ClassDefinition;
28 30
 import org.openzen.zenscript.codemodel.definition.EnumDefinition;
29 31
 import org.openzen.zenscript.codemodel.definition.InterfaceDefinition;
@@ -49,8 +51,6 @@ import org.openzen.zenscript.codemodel.type.StringTypeID;
49 51
 import org.openzen.zenscript.codemodel.type.TypeID;
50 52
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
51 53
 import org.openzen.zenscript.codemodel.type.storage.AutoStorageTag;
52
-import org.openzen.zenscript.compiler.ModuleSpace;
53
-import org.openzen.zenscript.compiler.SemanticModule;
54 54
 import org.openzen.zenscript.javashared.JavaClass;
55 55
 import org.openzen.zenscript.javashared.JavaCompiledModule;
56 56
 import org.openzen.zenscript.javashared.JavaField;

+ 11
- 10
JavaIntegration/src/main/java/org/openzen/zencode/java/ScriptingEngine.java Visa fil

@@ -13,13 +13,13 @@ import java.util.Map;
13 13
 import org.openzen.zencode.shared.CompileException;
14 14
 import org.openzen.zencode.shared.SourceFile;
15 15
 import org.openzen.zenscript.codemodel.Module;
16
+import org.openzen.zenscript.codemodel.ModuleSpace;
17
+import org.openzen.zenscript.codemodel.SemanticModule;
16 18
 import org.openzen.zenscript.codemodel.context.CompilingPackage;
17 19
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
18 20
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
19 21
 import org.openzen.zenscript.codemodel.type.ISymbol;
20 22
 import org.openzen.zenscript.codemodel.type.storage.StorageType;
21
-import org.openzen.zenscript.compiler.ModuleSpace;
22
-import org.openzen.zenscript.compiler.SemanticModule;
23 23
 import org.openzen.zenscript.javabytecode.JavaBytecodeRunUnit;
24 24
 import org.openzen.zenscript.javabytecode.JavaCompiler;
25 25
 import org.openzen.zenscript.javashared.SimpleJavaCompileSpace;
@@ -27,6 +27,7 @@ import org.openzen.zenscript.lexer.ParseException;
27 27
 import org.openzen.zenscript.parser.BracketExpressionParser;
28 28
 import org.openzen.zenscript.parser.ParsedFile;
29 29
 import org.openzen.zenscript.parser.ZippedPackage;
30
+import org.openzen.zenscript.validator.Validator;
30 31
 
31 32
 /**
32 33
  *
@@ -47,7 +48,7 @@ public class ScriptingEngine {
47 48
 		try {
48 49
 			ZippedPackage stdlibs = new ZippedPackage(ScriptingEngine.class.getResourceAsStream("/StdLibs.zip"));
49 50
 			SemanticModule stdlibModule = stdlibs.loadModule(space, "stdlib", null, new SemanticModule[0], stdlib);
50
-			stdlibModule.validate(error -> System.out.println(error.toString()));
51
+			stdlibModule = Validator.validate(stdlibModule, error -> System.out.println(error.toString()));
51 52
 			space.addModule("stdlib", stdlibModule);
52 53
 		} catch (IOException ex) {
53 54
 			throw new RuntimeException(ex);
@@ -64,8 +65,10 @@ public class ScriptingEngine {
64 65
 	}
65 66
 	
66 67
 	public void registerNativeProvided(JavaNativeModule module) throws CompileException {
67
-		SemanticModule semantic = module.toSemantic(space);
68
-		if (!semantic.validate(entry -> System.out.println(entry)))
68
+		SemanticModule semantic = Validator.validate(
69
+				module.toSemantic(space),
70
+				entry -> System.out.println(entry));
71
+		if (!semantic.isValid())
69 72
 			return;
70 73
 		
71 74
 		space.addModule(module.module.name, semantic);
@@ -102,11 +105,9 @@ public class ScriptingEngine {
102 105
 		if (!scripts.isValid())
103 106
 			return scripts;
104 107
 		
105
-		scripts = scripts.normalize();
106
-		if (!scripts.validate(error -> System.out.println(error.toString())))
107
-			return scripts;
108
-		
109
-		return scripts;
108
+		return Validator.validate(
109
+				scripts.normalize(),
110
+				error -> System.out.println(error.toString()));
110 111
 	}
111 112
 	
112 113
 	public void registerCompiled(SemanticModule module) {

+ 0
- 1
JavaShared/build.gradle Visa fil

@@ -15,5 +15,4 @@ if (!hasProperty('mainClass')) {
15 15
 
16 16
 dependencies {
17 17
 	compile project(':CodeModel')
18
-	compile project(':CompilerShared')
19 18
 }

+ 1
- 4
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaBaseCompiler.java Visa fil

@@ -1,8 +1,5 @@
1 1
 package org.openzen.zenscript.javashared;
2 2
 
3
-import org.openzen.zenscript.compiler.SemanticModule;
4
-import org.openzen.zenscript.compiler.ZenCodeCompiler;
5
-
6 3
 /*
7 4
  * To change this license header, choose License Headers in Project Properties.
8 5
  * To change this template file, choose Tools | Templates
@@ -13,6 +10,6 @@ import org.openzen.zenscript.compiler.ZenCodeCompiler;
13 10
  *
14 11
  * @author Hoofdgebruiker
15 12
  */
16
-public abstract class JavaBaseCompiler implements ZenCodeCompiler {
13
+public abstract class JavaBaseCompiler {
17 14
 	//public abstract JavaCompiledModule compile(SemanticModule module, JavaCompileSpace space);
18 15
 }

+ 1
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaDefinitionVisitor.java Visa fil

@@ -10,6 +10,7 @@ import java.util.List;
10 10
 import org.openzen.zencode.shared.CodePosition;
11 11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12 12
 import org.openzen.zenscript.codemodel.Modifiers;
13
+import org.openzen.zenscript.codemodel.SemanticModule;
13 14
 import org.openzen.zenscript.codemodel.definition.AliasDefinition;
14 15
 import org.openzen.zenscript.codemodel.definition.ClassDefinition;
15 16
 import org.openzen.zenscript.codemodel.definition.DefinitionVisitor;
@@ -31,7 +32,6 @@ import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
31 32
 import org.openzen.zenscript.codemodel.type.StoredType;
32 33
 import org.openzen.zenscript.codemodel.type.TypeID;
33 34
 import org.openzen.zenscript.compiler.CompileScope;
34
-import org.openzen.zenscript.compiler.SemanticModule;
35 35
 import org.openzen.zenscript.javasource.scope.JavaSourceFileScope;
36 36
 import org.openzen.zenscript.javasource.scope.JavaSourceStatementScope;
37 37
 import org.openzen.zenscript.javashared.JavaClass;

+ 1
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaMemberCompiler.java Visa fil

@@ -13,6 +13,7 @@ import org.openzen.zenscript.codemodel.FunctionHeader;
13 13
 import org.openzen.zenscript.codemodel.FunctionParameter;
14 14
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
15 15
 import org.openzen.zenscript.codemodel.Modifiers;
16
+import org.openzen.zenscript.codemodel.SemanticModule;
16 17
 import org.openzen.zenscript.codemodel.definition.InterfaceDefinition;
17 18
 import org.openzen.zenscript.codemodel.member.CallerMember;
18 19
 import org.openzen.zenscript.codemodel.member.CasterMember;
@@ -35,7 +36,6 @@ import org.openzen.zenscript.codemodel.statement.EmptyStatement;
35 36
 import org.openzen.zenscript.codemodel.statement.Statement;
36 37
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
37 38
 import org.openzen.zenscript.codemodel.type.storage.UniqueStorageTag;
38
-import org.openzen.zenscript.compiler.SemanticModule;
39 39
 import org.openzen.zenscript.javasource.scope.JavaSourceFileScope;
40 40
 import org.openzen.zenscript.javashared.JavaClass;
41 41
 import org.openzen.zenscript.javashared.JavaCompiledModule;

+ 1
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceCompiler.java Visa fil

@@ -11,8 +11,8 @@ import org.openzen.zencode.shared.SourceFile;
11 11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12 12
 import org.openzen.zenscript.codemodel.Module;
13 13
 import org.openzen.zenscript.codemodel.ScriptBlock;
14
+import org.openzen.zenscript.codemodel.SemanticModule;
14 15
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
15
-import org.openzen.zenscript.compiler.SemanticModule;
16 16
 import org.openzen.zenscript.javashared.prepare.JavaPrepareDefinitionVisitor;
17 17
 import org.openzen.zenscript.javashared.JavaClass;
18 18
 import org.openzen.zenscript.javashared.JavaCompileSpace;

+ 1
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceFile.java Visa fil

@@ -10,10 +10,10 @@ import org.openzen.zenscript.javashared.JavaContext;
10 10
 import java.util.ArrayList;
11 11
 import java.util.List;
12 12
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
13
+import org.openzen.zenscript.codemodel.SemanticModule;
13 14
 import org.openzen.zenscript.codemodel.annotations.NativeTag;
14 15
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
15 16
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
16
-import org.openzen.zenscript.compiler.SemanticModule;
17 17
 import org.openzen.zenscript.javashared.JavaClass;
18 18
 import org.openzen.zenscript.javashared.prepare.JavaPrepareDefinitionMemberVisitor;
19 19
 

+ 0
- 1
Parser/build.gradle Visa fil

@@ -16,5 +16,4 @@ if (!hasProperty('mainClass')) {
16 16
 dependencies {
17 17
     compile project(':Shared')
18 18
 	compile project(':CodeModel')
19
-	compile project(':CompilerShared')
20 19
 }

+ 2
- 2
Parser/src/main/java/org/openzen/zenscript/parser/ParsedFile.java Visa fil

@@ -19,8 +19,10 @@ import org.openzen.zencode.shared.LiteralSourceFile;
19 19
 import org.openzen.zencode.shared.SourceFile;
20 20
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
21 21
 import org.openzen.zenscript.codemodel.Modifiers;
22
+import org.openzen.zenscript.codemodel.ModuleSpace;
22 23
 import org.openzen.zenscript.codemodel.PackageDefinitions;
23 24
 import org.openzen.zenscript.codemodel.ScriptBlock;
25
+import org.openzen.zenscript.codemodel.SemanticModule;
24 26
 import org.openzen.zenscript.codemodel.WhitespacePostComment;
25 27
 import org.openzen.zenscript.codemodel.context.CompilingPackage;
26 28
 import org.openzen.zenscript.codemodel.context.FileResolutionContext;
@@ -34,8 +36,6 @@ import org.openzen.zenscript.codemodel.scope.FileScope;
34 36
 import org.openzen.zenscript.codemodel.scope.GlobalScriptScope;
35 37
 import org.openzen.zenscript.codemodel.type.ISymbol;
36 38
 import org.openzen.zenscript.codemodel.scope.StatementScope;
37
-import org.openzen.zenscript.compiler.ModuleSpace;
38
-import org.openzen.zenscript.compiler.SemanticModule;
39 39
 import org.openzen.zenscript.lexer.ParseException;
40 40
 import org.openzen.zenscript.parser.statements.ParsedStatement;
41 41
 

+ 2
- 2
Parser/src/main/java/org/openzen/zenscript/parser/ZippedPackage.java Visa fil

@@ -18,10 +18,10 @@ import java.util.zip.ZipInputStream;
18 18
 import org.openzen.zencode.shared.LiteralSourceFile;
19 19
 import org.openzen.zencode.shared.SourceFile;
20 20
 import org.openzen.zenscript.codemodel.Module;
21
+import org.openzen.zenscript.codemodel.ModuleSpace;
22
+import org.openzen.zenscript.codemodel.SemanticModule;
21 23
 import org.openzen.zenscript.codemodel.context.CompilingPackage;
22 24
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
23
-import org.openzen.zenscript.compiler.ModuleSpace;
24
-import org.openzen.zenscript.compiler.SemanticModule;
25 25
 import org.openzen.zenscript.lexer.ParseException;
26 26
 
27 27
 /**

+ 0
- 4
ScriptingExample/build.gradle Visa fil

@@ -14,9 +14,5 @@ if (!hasProperty('mainClass')) {
14 14
 }
15 15
 
16 16
 dependencies {
17
-	compile project(':Parser')
18
-	compile project(':JavaBytecodeCompiler')
19
-	compile project(':JavaShared')
20
-	compile project(':CodeFormatter')
21 17
     compile project(':JavaIntegration')
22 18
 }

+ 1
- 1
ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/Main.java Visa fil

@@ -9,7 +9,7 @@ import org.openzen.zencode.shared.CodePosition;
9 9
 import org.openzen.zencode.shared.CompileException;
10 10
 import org.openzen.zencode.shared.FileSourceFile;
11 11
 import org.openzen.zencode.shared.SourceFile;
12
-import org.openzen.zenscript.compiler.SemanticModule;
12
+import org.openzen.zenscript.codemodel.SemanticModule;
13 13
 import org.openzen.zenscript.lexer.ParseException;
14 14
 import org.openzen.zenscript.lexer.ZSToken;
15 15
 import org.openzen.zenscript.lexer.ZSTokenParser;

+ 33
- 0
Validator/src/main/java/org/openzen/zenscript/validator/Validator.java Visa fil

@@ -8,11 +8,13 @@ package org.openzen.zenscript.validator;
8 8
 import java.util.ArrayList;
9 9
 import java.util.Collections;
10 10
 import java.util.List;
11
+import java.util.function.Consumer;
11 12
 import org.openzen.zencode.shared.CodePosition;
12 13
 import org.openzen.zenscript.codemodel.AccessScope;
13 14
 import org.openzen.zenscript.codemodel.FunctionHeader;
14 15
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
15 16
 import org.openzen.zenscript.codemodel.ScriptBlock;
17
+import org.openzen.zenscript.codemodel.SemanticModule;
16 18
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
17 19
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
18 20
 import org.openzen.zenscript.codemodel.statement.Statement;
@@ -26,6 +28,37 @@ import org.openzen.zenscript.validator.visitors.StatementValidator;
26 28
  * @author Hoofdgebruiker
27 29
  */
28 30
 public class Validator {
31
+	public static SemanticModule validate(SemanticModule module, Consumer<ValidationLogEntry> logger) {
32
+		if (module.state != SemanticModule.State.NORMALIZED)
33
+			throw new IllegalStateException("Module is not yet normalized");
34
+		
35
+		Validator validator = new Validator(module.registry, module.expansions, module.annotations);
36
+		for (ScriptBlock script : module.scripts) {
37
+			validator.validate(script);
38
+		}
39
+		for (HighLevelDefinition definition : module.definitions.getAll()) {
40
+			validator.validate(definition);
41
+		}
42
+		
43
+		for (ValidationLogEntry entry : validator.getLog()) {
44
+			logger.accept(entry);
45
+		}
46
+		
47
+		SemanticModule.State state = validator.hasErrors() ? SemanticModule.State.INVALID : SemanticModule.State.VALIDATED;
48
+		return new SemanticModule(
49
+				module.module,
50
+				module.dependencies,
51
+				state,
52
+				module.rootPackage,
53
+				module.modulePackage,
54
+				module.definitions,
55
+				module.scripts,
56
+				module.registry,
57
+				module.expansions,
58
+				module.annotations,
59
+				module.storageTypes);
60
+	}
61
+	
29 62
 	private final List<ValidationLogEntry> log = new ArrayList<>();
30 63
 	public final GlobalTypeRegistry registry;
31 64
 	public final List<ExpansionDefinition> expansions;

Loading…
Avbryt
Spara