Browse Source

Simplified dependencies and the build tree with some minor refactoring.

Stan Hebben 6 years ago
parent
commit
3094e93529
30 changed files with 85 additions and 94 deletions
  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 View File

3
  * To change this template file, choose Tools | Templates
3
  * To change this template file, choose Tools | Templates
4
  * and open the template in the editor.
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
 import java.util.ArrayList;
8
 import java.util.ArrayList;
9
 import java.util.HashMap;
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 View File

3
  * To change this template file, choose Tools | Templates
3
  * To change this template file, choose Tools | Templates
4
  * and open the template in the editor.
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
 import java.util.ArrayList;
8
 import java.util.ArrayList;
9
 import java.util.HashMap;
9
 import java.util.HashMap;
10
 import java.util.List;
10
 import java.util.List;
11
 import java.util.Map;
11
 import java.util.Map;
12
-import java.util.function.Consumer;
13
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
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
 import org.openzen.zenscript.codemodel.annotations.AnnotationProcessor;
13
 import org.openzen.zenscript.codemodel.annotations.AnnotationProcessor;
19
 import org.openzen.zenscript.codemodel.context.ModuleContext;
14
 import org.openzen.zenscript.codemodel.context.ModuleContext;
20
 import org.openzen.zenscript.codemodel.context.ModuleTypeResolutionContext;
15
 import org.openzen.zenscript.codemodel.context.ModuleTypeResolutionContext;
24
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
19
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
25
 import org.openzen.zenscript.codemodel.type.ISymbol;
20
 import org.openzen.zenscript.codemodel.type.ISymbol;
26
 import org.openzen.zenscript.codemodel.type.storage.StorageType;
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
 	public final String name;
30
 	public final String name;
38
 	public final SemanticModule[] dependencies;
31
 	public final SemanticModule[] dependencies;
39
 	
32
 	
40
-	private State state;
33
+	public final State state;
41
 	public final Module module;
34
 	public final Module module;
42
 	public final ZSPackage rootPackage;
35
 	public final ZSPackage rootPackage;
43
 	public final ZSPackage modulePackage;
36
 	public final ZSPackage modulePackage;
114
 				storageTypes);
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
 	public ModuleContext getContext() {
110
 	public ModuleContext getContext() {
144
 		return new ModuleContext(registry, module, expansions, rootPackage);
111
 		return new ModuleContext(registry, module, expansions, rootPackage);
145
 	}
112
 	}

+ 2
- 0
CompilerShared/src/main/java/org/openzen/zenscript/compiler/ModuleReference.java View File

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

+ 1
- 0
CompilerShared/src/main/java/org/openzen/zenscript/compiler/ModuleRegistry.java View File

13
 import org.openzen.zencode.shared.CodePosition;
13
 import org.openzen.zencode.shared.CodePosition;
14
 import org.openzen.zencode.shared.CompileException;
14
 import org.openzen.zencode.shared.CompileException;
15
 import org.openzen.zencode.shared.CompileExceptionCode;
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 View File

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

+ 2
- 0
CompilerShared/src/main/java/org/openzen/zenscript/compiler/ZenCodeCompiler.java View File

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

+ 1
- 1
Constructor/src/main/java/org/openzen/zenscript/constructor/ConstructorRegistry.java View File

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

+ 1
- 1
Constructor/src/main/java/org/openzen/zenscript/constructor/ModuleLoader.java View File

11
 import java.util.Stack;
11
 import java.util.Stack;
12
 import java.util.function.Consumer;
12
 import java.util.function.Consumer;
13
 import org.openzen.zencode.shared.CompileException;
13
 import org.openzen.zencode.shared.CompileException;
14
+import org.openzen.zenscript.codemodel.SemanticModule;
14
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
15
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
15
 import org.openzen.zenscript.constructor.module.ModuleReference;
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 View File

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

+ 1
- 1
Constructor/src/main/java/org/openzen/zenscript/constructor/module/ModuleReference.java View File

7
 
7
 
8
 import java.util.function.Consumer;
8
 import java.util.function.Consumer;
9
 import org.openzen.zencode.shared.CompileException;
9
 import org.openzen.zencode.shared.CompileException;
10
+import org.openzen.zenscript.codemodel.SemanticModule;
10
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
11
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
11
-import org.openzen.zenscript.compiler.SemanticModule;
12
 import org.openzen.zenscript.constructor.ModuleLoader;
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 View File

6
 package org.openzen.zenscript.ide.host.local;
6
 package org.openzen.zenscript.ide.host.local;
7
 
7
 
8
 import java.util.function.Consumer;
8
 import java.util.function.Consumer;
9
-import org.openzen.zenscript.compiler.SemanticModule;
9
+import org.openzen.zenscript.codemodel.SemanticModule;
10
 import org.openzen.zenscript.constructor.ModuleLoader;
10
 import org.openzen.zenscript.constructor.ModuleLoader;
11
 import org.openzen.zenscript.constructor.module.ModuleReference;
11
 import org.openzen.zenscript.constructor.module.ModuleReference;
12
 import org.openzen.zenscript.ide.codemodel.IDECodeError;
12
 import org.openzen.zenscript.ide.codemodel.IDECodeError;
13
 import org.openzen.zenscript.ide.host.IDEModule;
13
 import org.openzen.zenscript.ide.host.IDEModule;
14
 import org.openzen.zenscript.ide.host.IDEPackage;
14
 import org.openzen.zenscript.ide.host.IDEPackage;
15
+import org.openzen.zenscript.validator.Validator;
15
 
16
 
16
 /**
17
 /**
17
  *
18
  *
39
 	@Override
40
 	@Override
40
 	public void prebuild(ModuleLoader loader, Consumer<IDECodeError> errors) {
41
 	public void prebuild(ModuleLoader loader, Consumer<IDECodeError> errors) {
41
 		SemanticModule module = loader.getModule(this.module.getName());
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 View File

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

+ 1
- 7
JavaAnnotations/build.gradle View File

14
 }
14
 }
15
 
15
 
16
 dependencies {
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 View File

16
 dependencies {
16
 dependencies {
17
 	compile 'org.ow2.asm:asm-debug-all:6.0_BETA'
17
 	compile 'org.ow2.asm:asm-debug-all:6.0_BETA'
18
 	compile project(':CodeModel')
18
 	compile project(':CodeModel')
19
-	compile project(':CompilerShared')
20
 	compile project(':JavaShared')
19
 	compile project(':JavaShared')
21
 }
20
 }

+ 1
- 1
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaCompiler.java View File

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

+ 1
- 1
JavaIntegration/build.gradle View File

15
 
15
 
16
 dependencies {
16
 dependencies {
17
 	compile project(':CodeModel')
17
 	compile project(':CodeModel')
18
-	compile project(':CompilerShared')
19
 	compile project(':Parser')
18
 	compile project(':Parser')
20
 	compile project(':JavaBytecodeCompiler')
19
 	compile project(':JavaBytecodeCompiler')
21
 	compile project(':JavaAnnotations')
20
 	compile project(':JavaAnnotations')
21
+	compile project(':Validator')
22
 }
22
 }

+ 2
- 2
JavaIntegration/src/main/java/org/openzen/zencode/java/JavaNativeModule.java View File

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

+ 11
- 10
JavaIntegration/src/main/java/org/openzen/zencode/java/ScriptingEngine.java View File

13
 import org.openzen.zencode.shared.CompileException;
13
 import org.openzen.zencode.shared.CompileException;
14
 import org.openzen.zencode.shared.SourceFile;
14
 import org.openzen.zencode.shared.SourceFile;
15
 import org.openzen.zenscript.codemodel.Module;
15
 import org.openzen.zenscript.codemodel.Module;
16
+import org.openzen.zenscript.codemodel.ModuleSpace;
17
+import org.openzen.zenscript.codemodel.SemanticModule;
16
 import org.openzen.zenscript.codemodel.context.CompilingPackage;
18
 import org.openzen.zenscript.codemodel.context.CompilingPackage;
17
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
19
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
18
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
20
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
19
 import org.openzen.zenscript.codemodel.type.ISymbol;
21
 import org.openzen.zenscript.codemodel.type.ISymbol;
20
 import org.openzen.zenscript.codemodel.type.storage.StorageType;
22
 import org.openzen.zenscript.codemodel.type.storage.StorageType;
21
-import org.openzen.zenscript.compiler.ModuleSpace;
22
-import org.openzen.zenscript.compiler.SemanticModule;
23
 import org.openzen.zenscript.javabytecode.JavaBytecodeRunUnit;
23
 import org.openzen.zenscript.javabytecode.JavaBytecodeRunUnit;
24
 import org.openzen.zenscript.javabytecode.JavaCompiler;
24
 import org.openzen.zenscript.javabytecode.JavaCompiler;
25
 import org.openzen.zenscript.javashared.SimpleJavaCompileSpace;
25
 import org.openzen.zenscript.javashared.SimpleJavaCompileSpace;
27
 import org.openzen.zenscript.parser.BracketExpressionParser;
27
 import org.openzen.zenscript.parser.BracketExpressionParser;
28
 import org.openzen.zenscript.parser.ParsedFile;
28
 import org.openzen.zenscript.parser.ParsedFile;
29
 import org.openzen.zenscript.parser.ZippedPackage;
29
 import org.openzen.zenscript.parser.ZippedPackage;
30
+import org.openzen.zenscript.validator.Validator;
30
 
31
 
31
 /**
32
 /**
32
  *
33
  *
47
 		try {
48
 		try {
48
 			ZippedPackage stdlibs = new ZippedPackage(ScriptingEngine.class.getResourceAsStream("/StdLibs.zip"));
49
 			ZippedPackage stdlibs = new ZippedPackage(ScriptingEngine.class.getResourceAsStream("/StdLibs.zip"));
49
 			SemanticModule stdlibModule = stdlibs.loadModule(space, "stdlib", null, new SemanticModule[0], stdlib);
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
 			space.addModule("stdlib", stdlibModule);
52
 			space.addModule("stdlib", stdlibModule);
52
 		} catch (IOException ex) {
53
 		} catch (IOException ex) {
53
 			throw new RuntimeException(ex);
54
 			throw new RuntimeException(ex);
64
 	}
65
 	}
65
 	
66
 	
66
 	public void registerNativeProvided(JavaNativeModule module) throws CompileException {
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
 			return;
72
 			return;
70
 		
73
 		
71
 		space.addModule(module.module.name, semantic);
74
 		space.addModule(module.module.name, semantic);
102
 		if (!scripts.isValid())
105
 		if (!scripts.isValid())
103
 			return scripts;
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
 	public void registerCompiled(SemanticModule module) {
113
 	public void registerCompiled(SemanticModule module) {

+ 0
- 1
JavaShared/build.gradle View File

15
 
15
 
16
 dependencies {
16
 dependencies {
17
 	compile project(':CodeModel')
17
 	compile project(':CodeModel')
18
-	compile project(':CompilerShared')
19
 }
18
 }

+ 1
- 4
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaBaseCompiler.java View File

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

+ 1
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaDefinitionVisitor.java View File

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

+ 1
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaMemberCompiler.java View File

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

+ 1
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceCompiler.java View File

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

+ 1
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceFile.java View File

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

+ 0
- 1
Parser/build.gradle View File

16
 dependencies {
16
 dependencies {
17
     compile project(':Shared')
17
     compile project(':Shared')
18
 	compile project(':CodeModel')
18
 	compile project(':CodeModel')
19
-	compile project(':CompilerShared')
20
 }
19
 }

+ 2
- 2
Parser/src/main/java/org/openzen/zenscript/parser/ParsedFile.java View File

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

+ 2
- 2
Parser/src/main/java/org/openzen/zenscript/parser/ZippedPackage.java View File

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

+ 0
- 4
ScriptingExample/build.gradle View File

14
 }
14
 }
15
 
15
 
16
 dependencies {
16
 dependencies {
17
-	compile project(':Parser')
18
-	compile project(':JavaBytecodeCompiler')
19
-	compile project(':JavaShared')
20
-	compile project(':CodeFormatter')
21
     compile project(':JavaIntegration')
17
     compile project(':JavaIntegration')
22
 }
18
 }

+ 1
- 1
ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/Main.java View File

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

+ 33
- 0
Validator/src/main/java/org/openzen/zenscript/validator/Validator.java View File

8
 import java.util.ArrayList;
8
 import java.util.ArrayList;
9
 import java.util.Collections;
9
 import java.util.Collections;
10
 import java.util.List;
10
 import java.util.List;
11
+import java.util.function.Consumer;
11
 import org.openzen.zencode.shared.CodePosition;
12
 import org.openzen.zencode.shared.CodePosition;
12
 import org.openzen.zenscript.codemodel.AccessScope;
13
 import org.openzen.zenscript.codemodel.AccessScope;
13
 import org.openzen.zenscript.codemodel.FunctionHeader;
14
 import org.openzen.zenscript.codemodel.FunctionHeader;
14
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
15
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
15
 import org.openzen.zenscript.codemodel.ScriptBlock;
16
 import org.openzen.zenscript.codemodel.ScriptBlock;
17
+import org.openzen.zenscript.codemodel.SemanticModule;
16
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
18
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
17
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
19
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
18
 import org.openzen.zenscript.codemodel.statement.Statement;
20
 import org.openzen.zenscript.codemodel.statement.Statement;
26
  * @author Hoofdgebruiker
28
  * @author Hoofdgebruiker
27
  */
29
  */
28
 public class Validator {
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
 	private final List<ValidationLogEntry> log = new ArrayList<>();
62
 	private final List<ValidationLogEntry> log = new ArrayList<>();
30
 	public final GlobalTypeRegistry registry;
63
 	public final GlobalTypeRegistry registry;
31
 	public final List<ExpansionDefinition> expansions;
64
 	public final List<ExpansionDefinition> expansions;

Loading…
Cancel
Save