Simplify compiler classes and add MP Compiler

This commit is contained in:
peterdell 2021-09-26 16:05:27 +02:00
parent 11722d1939
commit d9b833c87e
24 changed files with 187 additions and 101 deletions

View File

@ -5,6 +5,7 @@ Bundle-SymbolicName: com.wudsn.ide.lng.asm.test;singleton:=true
Bundle-Version: 1.7.2.qualifier
Bundle-Vendor: Peter Dell
Bundle-RequiredExecutionEnvironment: JavaSE-11
Require-Bundle: com.wudsn.ide.lng
Require-Bundle: com.wudsn.ide.lng,
com.wudsn.ide.lng.asm
Bundle-ActivationPolicy: lazy
Automatic-Module-Name: com.wudsn.ide.asm.compilers.test

View File

@ -4,7 +4,7 @@
<extension
point="org.eclipse.ui.preferencePages">
<page
category="com.wudsn.ide.lng.preferences.AssemblerPreferencesPage"
category="com.wudsn.ide.lng.asm.preferences.AssemblerPreferencesPage"
class="com.wudsn.ide.lng.asm.preferences.AssemblerPreferencesTestCompilersPage"
id="com.wudsn.ide.lng.asm.preferences.AssemblerPreferencesTestCompilersPage"
name="%com.wudsn.ide.lng.asm.preferences.AssemblerPreferencesTestCompilersPage.name">

View File

@ -11,8 +11,4 @@ public final class TestEditor extends LanguageEditor {
}
@Override
public String getCompilerId() {
return "test";
}
}

View File

@ -58,6 +58,7 @@
helpFilePaths="./docs"
homePageURL="https://sourceforge.net/projects/acme-crossass"
id="acme"
language="ASM"
name="%com.wudsn.ide.lng.asm.compiler.acme.AcmeCompiler.name"
version="0.90 (preview)">
<supportedTarget
@ -81,6 +82,7 @@
helpFilePaths="./README.TXT"
homePageURL="http://3dscapture.com/NES/asm6.zip"
id="asm6"
language="ASM"
name="%com.wudsn.ide.lng.asm.compiler.asm6.Asm6Compiler.name"
version="1.6">
<supportedTarget
@ -97,6 +99,7 @@
helpFilePaths="./docs/atasm.pdf"
homePageURL="http://atari.miribilist.com/atasm"
id="atasm"
language="ASM"
name="%com.wudsn.ide.lng.asm.compiler.atasm.AtasmCompiler.name"
version="1.07">
<supportedTarget
@ -113,6 +116,7 @@
helpFilePaths="../doc/dasm.TXT"
homePageURL="http://dasm-dillon.sourceforge.net"
id="dasm"
language="ASM"
name="%com.wudsn.ide.lng.asm.compiler.dasm.DasmCompiler.name"
version="2.20.10 (preview)">
<supportedTarget
@ -129,6 +133,7 @@
helpFilePaths="./KickAssembler.pdf"
homePageURL="http://www.theweb.dk/KickAssembler"
id="kickass"
language="ASM"
name="%com.wudsn.ide.lng.asm.compiler.kickass.KickAssCompiler.name"
version="V3.21 (preview)">
<supportedTarget
@ -148,6 +153,7 @@
helpFilePaths="./doc/mads-en.html, ./doc/mads.html (pl)"
homePageURL="http://mads.atari8.info"
id="mads"
language="ASM"
name="%com.wudsn.ide.lng.asm.compiler.mads.MadsCompiler.name"
version="1.9.0">
<supportedTarget
@ -167,6 +173,7 @@
helpFilePaths="../Documentation/Merlin32.pdf"
homePageURL="http://www.brutaldeluxe.fr/products/crossdevtools/merlin/index.html"
id="merlin32"
language="ASM"
name="%com.wudsn.ide.lng.asm.compiler.merlin32.Merlin32Compiler.name"
version="1.0">
<supportedTarget
@ -186,6 +193,7 @@
helpFilePaths="./README"
homePageURL="http://tass64.sourceforge.net"
id="tass"
language="ASM"
name="%com.wudsn.ide.lng.asm.compiler.tass.TassCompiler.name"
version="1.46 r38 (preview)">
<supportedTarget
@ -206,6 +214,7 @@
helpFilePaths="./xasm.html"
homePageURL="https://github.com/pfusik/xasm"
id="xasm"
language="ASM"
name="%com.wudsn.ide.lng.asm.compiler.xasm.XasmCompiler.name"
version="3.0.2">
<supportedTarget

View File

@ -19,7 +19,6 @@
package com.wudsn.ide.lng.asm.compiler.acme;
import com.wudsn.ide.lng.asm.compiler.CompilerId;
import com.wudsn.ide.lng.editor.LanguageEditor;
public final class AcmeEditor extends LanguageEditor {
@ -29,9 +28,4 @@ public final class AcmeEditor extends LanguageEditor {
*/
public AcmeEditor() {
}
@Override
public String getCompilerId() {
return CompilerId.ACME;
}
}

View File

@ -19,7 +19,6 @@
package com.wudsn.ide.lng.asm.compiler.asm6;
import com.wudsn.ide.lng.asm.compiler.CompilerId;
import com.wudsn.ide.lng.editor.LanguageEditor;
public final class Asm6Editor extends LanguageEditor {
@ -30,8 +29,4 @@ public final class Asm6Editor extends LanguageEditor {
public Asm6Editor() {
}
@Override
public String getCompilerId() {
return CompilerId.ASM6;
}
}

View File

@ -19,7 +19,6 @@
package com.wudsn.ide.lng.asm.compiler.atasm;
import com.wudsn.ide.lng.asm.compiler.CompilerId;
import com.wudsn.ide.lng.editor.LanguageEditor;
public final class AtasmEditor extends LanguageEditor {
@ -29,9 +28,4 @@ public final class AtasmEditor extends LanguageEditor {
*/
public AtasmEditor() {
}
@Override
public String getCompilerId() {
return CompilerId.ATASM;
}
}

View File

@ -19,7 +19,6 @@
package com.wudsn.ide.lng.asm.compiler.dasm;
import com.wudsn.ide.lng.asm.compiler.CompilerId;
import com.wudsn.ide.lng.editor.LanguageEditor;
public final class DasmEditor extends LanguageEditor {
@ -30,8 +29,4 @@ public final class DasmEditor extends LanguageEditor {
public DasmEditor() {
}
@Override
public String getCompilerId() {
return CompilerId.DASM;
}
}

View File

@ -19,7 +19,6 @@
package com.wudsn.ide.lng.asm.compiler.kickass;
import com.wudsn.ide.lng.asm.compiler.CompilerId;
import com.wudsn.ide.lng.editor.LanguageEditor;
public final class KickAssEditor extends LanguageEditor {
@ -31,8 +30,4 @@ public final class KickAssEditor extends LanguageEditor {
}
@Override
public String getCompilerId() {
return CompilerId.KICKASS;
}
}

View File

@ -19,7 +19,6 @@
package com.wudsn.ide.lng.asm.compiler.mads;
import com.wudsn.ide.lng.asm.compiler.CompilerId;
import com.wudsn.ide.lng.editor.LanguageEditor;
public final class MadsEditor extends LanguageEditor {
@ -31,8 +30,4 @@ public final class MadsEditor extends LanguageEditor {
}
@Override
public String getCompilerId() {
return CompilerId.MADS;
}
}

View File

@ -19,7 +19,6 @@
package com.wudsn.ide.lng.asm.compiler.merlin32;
import com.wudsn.ide.lng.asm.compiler.CompilerId;
import com.wudsn.ide.lng.editor.LanguageEditor;
public final class Merlin32Editor extends LanguageEditor {
@ -31,8 +30,5 @@ public final class Merlin32Editor extends LanguageEditor {
}
@Override
public String getCompilerId() {
return CompilerId.MERLIN32;
}
}

View File

@ -19,7 +19,6 @@
package com.wudsn.ide.lng.asm.compiler.tass;
import com.wudsn.ide.lng.asm.compiler.CompilerId;
import com.wudsn.ide.lng.editor.LanguageEditor;
public final class TassEditor extends LanguageEditor {
@ -31,8 +30,4 @@ public final class TassEditor extends LanguageEditor {
}
@Override
public String getCompilerId() {
return CompilerId.TASS;
}
}

View File

@ -19,7 +19,6 @@
package com.wudsn.ide.lng.asm.compiler.xasm;
import com.wudsn.ide.lng.asm.compiler.CompilerId;
import com.wudsn.ide.lng.editor.LanguageEditor;
public final class XasmEditor extends LanguageEditor {
@ -31,8 +30,4 @@ public final class XasmEditor extends LanguageEditor {
}
@Override
public String getCompilerId() {
return CompilerId.XASM;
}
}

View File

@ -76,12 +76,12 @@ public final class CompilerDefinition implements Comparable<CompilerDefinition>
}
/**
* Gets the key that uniquely identifies the compiler. They key has the format
* Gets the key that uniquely identifies a compiler. They key has the format
* "<language>/<id>".
*
* @return The key that uniquely identifies the compiler, not <code>null</code>.
*/
public String getKey() {
public static String getKey(String language, String id) {
if (language == null) {
throw new IllegalStateException("Field 'language' must not be null for this or for argument.");
}
@ -92,6 +92,16 @@ public final class CompilerDefinition implements Comparable<CompilerDefinition>
return language + "/" + id;
}
/**
* Gets the key that uniquely identifies the compiler. They key has the format
* "<language>/<id>".
*
* @return The key that uniquely identifies the compiler, not <code>null</code>.
*/
public String getKey() {
return getKey(language, id);
}
/**
* Sets the language of the compiler. Called by {@link CompilerRegistry} only.
*

View File

@ -93,7 +93,7 @@ public final class CompilerRegistry {
try {
CompilerDefinition compilerDefinition;
compilerDefinition = new CompilerDefinition();
compilerDefinition.setId(configurationElement.getAttribute("language"));
compilerDefinition.setLanguage(configurationElement.getAttribute("language"));
compilerDefinition.setId(configurationElement.getAttribute("id"));
compilerDefinition.setName(configurationElement.getAttribute("name"));
compilerDefinition.setClassName(configurationElement.getAttribute("class"));
@ -145,13 +145,13 @@ public final class CompilerRegistry {
throw new IllegalArgumentException("Parameter 'compilerDefinition' must not be null.");
}
String id = compilerDefinition.getId();
String key = compilerDefinition.getKey();
Compiler compiler;
try {
// The class loading must be delegated to the framework.
compiler = (Compiler) configurationElement.createExecutableExtension("class");
} catch (CoreException ex) {
throw new RuntimeException("Cannot create compiler instance for id '" + id + "'.", ex);
throw new RuntimeException("Cannot create compiler instance for key '" + key + "'.", ex);
}
// Build the list of common and specific syntax definition files.
@ -160,7 +160,7 @@ public final class CompilerRegistry {
compilerClasses.add(Compiler.class);
CompilerSyntax syntax;
syntax = new CompilerSyntax(id);
syntax = new CompilerSyntax(key);
syntax.loadXMLData(compilerClasses);
@ -168,27 +168,66 @@ public final class CompilerRegistry {
compiler.setDefinition(compilerDefinition);
compiler = compilerMap.put(id, compiler);
compiler = compilerMap.put(key, compiler);
if (compiler != null) {
throw new RuntimeException(
"Compiler id '" + id + "' is already registered to class '" + compiler.getClass().getName() + "'.");
throw new RuntimeException("Compiler id '" + key + "' is already registered to class '"
+ compiler.getClass().getName() + "'.");
}
}
/**
* Gets the unmodifiable list of compiler definitions for a language, sorted by their key.
* Gets the unmodifiable list of compiler definitions for a language, sorted by
* their key.
*
* @param language The language or <code>null</code>.
* @param language The language, not <code>null</code>.
* @return The unmodifiable list of compiler definitions, sorted by their key,
* may be empty, not <code>null</code>
*
* @since 1.6.1
*/
public List<CompilerDefinition> getCompilerDefinitions(Language language) {
if (language == null) {
throw new IllegalArgumentException("Parameter 'language' must not be null.");
}
List<CompilerDefinition> result = new ArrayList<CompilerDefinition>();
for (CompilerDefinition compilerDefinition : compilerDefinitionList) {
if (compilerDefinition.getLanguage().equals(language.name())) {
result.add(compilerDefinition);
}
}
return Collections.unmodifiableList(result);
}
/**
* Gets the compiler for a given class. Instances of compiler are stateless
* singletons within the plugin.
*
* @param key The compiler key, not <code>null</code>.
*
* @return The compiler, not <code>null</code>.
*/
public Compiler getCompilerByEditorClassName(String editorClassName) {
if (editorClassName == null) {
throw new IllegalArgumentException("Parameter 'editorClassName' must not be null.");
}
final String SUFFIX = "Editor";
int index = editorClassName.lastIndexOf(SUFFIX);
if (index < 0 || index + SUFFIX.length() != editorClassName.length()) {
throw new IllegalArgumentException("Parameter 'editorClassName' must end with 'Editor'.");
}
String compilerClassName = editorClassName.substring(0, index) + "Compiler";
synchronized (compilerMap) {
for (Compiler compiler : compilerMap.values()) {
if (compiler.getClass().getName().equals(compilerClassName)) {
return compiler;
}
}
}
throw new IllegalArgumentException("Unknown compiler class '" + compilerClassName + "'.");
List<CompilerDefinition> result=new ArrayList<CompilerDefinition>();
return compilerDefinitionList;
}
/**
@ -199,13 +238,12 @@ public final class CompilerRegistry {
*
* @return The compiler, not <code>null</code>.
*/
public Compiler getCompiler(String key) {
public Compiler getCompilerByKey(String key) {
if (key == null) {
throw new IllegalArgumentException("Parameter 'key' must not be null.");
}
Compiler result;
synchronized (compilerMap) {
result = compilerMap.get(key);
}
if (result == null) {

View File

@ -48,7 +48,6 @@ import org.eclipse.ui.editors.text.TextEditor;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
import org.eclipse.ui.texteditor.TextOperationAction;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
@ -130,14 +129,13 @@ public abstract class LanguageEditor extends TextEditor {
*
* @return The compiler id for this editor, not empty and not <code>null</code>.
*/
protected abstract String getCompilerId();
@Override
protected final void initializeEditor() {
super.initializeEditor();
plugin = LanguagePlugin.getInstance();
compiler = plugin.getCompilerRegistry().getCompiler(getCompilerId());
compiler = plugin.getCompilerRegistry().getCompilerByEditorClassName(getClass().getName());
setSourceViewerConfiguration(new LanguageSourceViewerConfiguration(this, getPreferenceStore()));
@ -161,7 +159,7 @@ public abstract class LanguageEditor extends TextEditor {
* @return The compiler preferences, not <code>null</code>.
*/
public final CompilerPreferences getCompilerPreferences() {
return plugin.getPreferences().getCompilerPreferences(getCompilerId(), getHardware());
return plugin.getPreferences().getCompilerPreferences(getCompilerDefinition(), getHardware());
}
/**

View File

@ -244,6 +244,13 @@ public final class LanguageHelpContentProducer implements IHelpContentProducer {
return params;
}
/**
* Gets the input stream for a compiler.
*
* @param href Hyperlink reference in the form
* /compiler/<language>/<compilerId>/section.
* @return The input stream or <code>null</code> if the path is not valid.
*/
private InputStream getCompilerInputStream(String href) {
if (href == null) {
throw new IllegalArgumentException("Parameter 'href' must not be null.");
@ -257,13 +264,22 @@ public final class LanguageHelpContentProducer implements IHelpContentProducer {
if (index <= 0) {
return null;
}
String language = path.substring(0, index);
path = path.substring(index + 1);
index = path.indexOf("/");
if (index <= 0) {
return null;
}
String compilerId = path.substring(0, index);
String section = path.substring(index + 1);
path = path.substring(index + 1);
String section = path;
LanguagePlugin languagePlugin = LanguagePlugin.getInstance();
CompilerRegistry compilerRegistry = languagePlugin.getCompilerRegistry();
// Find non-empty compiler executable path.
Compiler compiler = compilerRegistry.getCompiler(compilerId);
String compilerKey = CompilerDefinition.getKey(language, compilerId);
Compiler compiler = compilerRegistry.getCompilerByKey(compilerKey);
if (section.startsWith(SECTION_GENERAL)) {
return getInputStream(getCompilerGeneralSection(compiler));
@ -594,7 +610,7 @@ public final class LanguageHelpContentProducer implements IHelpContentProducer {
return getInputStream(writer);
}
private InputStream getCPUInputStream( Language language, String href) {
private InputStream getCPUInputStream(Language language, String href) {
if (href == null) {
throw new IllegalArgumentException("Parameter 'href' must not be null.");

View File

@ -255,13 +255,15 @@ public final class LanguageTocProvider extends AbstractTocProvider {
for (int i = 0; i < size; i++) {
CompilerDefinition compilerDefinition = compilerDefinitions.get(i);
String href = LanguageHelpContentProducer.SCHEMA_COMPILER + compilerDefinition.getId() + "/"
+ LanguageHelpContentProducer.SECTION_GENERAL + LanguageHelpContentProducer.EXTENSION;
String hrefCompiler = LanguageHelpContentProducer.SCHEMA_COMPILER + compilerDefinition.getLanguage() + "/"
+ compilerDefinition.getId() + "/";
String href = hrefCompiler + LanguageHelpContentProducer.SECTION_GENERAL
+ LanguageHelpContentProducer.EXTENSION;
ITopic generalTopic = createTopic("", Texts.TOC_COMPILER_GENERAL_TOPIC_LABEL, href, null);
href = LanguageHelpContentProducer.SCHEMA_COMPILER + compilerDefinition.getId() + "/"
+ LanguageHelpContentProducer.SECTION_INSTRUCTIONS + LanguageHelpContentProducer.EXTENSION;
href = hrefCompiler + LanguageHelpContentProducer.SECTION_INSTRUCTIONS
+ LanguageHelpContentProducer.EXTENSION;
ITopic opcodesTopic = createTopic("", Texts.TOC_COMPILER_INSTRUCTIONS_TOPIC_LABEL, href, null);
LanguagePreferences languagePreferences = LanguagePlugin.getInstance().getPreferences();
@ -286,8 +288,7 @@ public final class LanguageTocProvider extends AbstractTocProvider {
extension = ".html";
}
href = LanguageHelpContentProducer.SCHEMA_COMPILER + compilerDefinition.getId() + "/"
+ LanguageHelpContentProducer.SECTION_MANUAL + extension;
href = hrefCompiler + LanguageHelpContentProducer.SECTION_MANUAL + extension;
if (file.isDirectory()) {
File[] files = file.listFiles();
@ -310,8 +311,7 @@ public final class LanguageTocProvider extends AbstractTocProvider {
href = "";
}
} catch (CoreException ex) {
href = LanguageHelpContentProducer.SCHEMA_COMPILER + compilerDefinition.getId() + "/"
+ LanguageHelpContentProducer.SECTION_MANUAL + ".html";
href = hrefCompiler + LanguageHelpContentProducer.SECTION_MANUAL + ".html";
}
ITopic manualTopic = createTopic(icon, Texts.TOC_COMPILER_MANUAL_TOPIC_LABEL, href,

View File

@ -25,9 +25,9 @@ import org.eclipse.jface.text.TextAttribute;
import com.wudsn.ide.base.common.AbstractIDEPlugin;
import com.wudsn.ide.base.common.StringUtility;
import com.wudsn.ide.base.hardware.Hardware;
import com.wudsn.ide.lng.compiler.CompilerDefinition;
import com.wudsn.ide.lng.editor.LanguageContentAssistProcessorDefaultCase;
import com.wudsn.ide.lng.editor.LanguageEditorCompileCommandPositioningMode;
/**
* Facade class for typed access to the plugin preferences.
*
@ -109,23 +109,21 @@ public final class LanguagePreferences {
/**
* Gets the preferences for a compiler.
*
* @param compilerId The compiler id, not empty and not <code>null</code>.
* @param compilerDefinition The compiler definition, not empty and not <code>null</code>.
* @param hardware The preferences or <code>null</code> if the compiler is not
* active for that hardware.
*
* @return The compiler preferences, not <code>null</code>.
*/
public CompilerPreferences getCompilerPreferences(String compilerId, Hardware hardware) {
if (compilerId == null) {
throw new IllegalArgumentException("Parameter 'compilerId' must not be null.");
}
if (StringUtility.isEmpty(compilerId)) {
throw new IllegalArgumentException("Parameter 'compilerId' must not be empty.");
public CompilerPreferences getCompilerPreferences(CompilerDefinition compilerDefinition, Hardware hardware) {
if (compilerDefinition == null) {
throw new IllegalArgumentException("Parameter 'compilerDefinition' must not be null.");
}
if (hardware == null) {
throw new IllegalArgumentException("Parameter 'hardware' must not be null.");
}
return new CompilerPreferences(this, compilerId, hardware);
return new CompilerPreferences(this, compilerDefinition.getId(), hardware);
}

View File

@ -19,7 +19,6 @@
package com.wudsn.ide.base.common;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

View File

@ -20,7 +20,6 @@ package com.wudsn.ide.base.gui;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

View File

@ -106,5 +106,21 @@
class="com.wudsn.ide.lng.pas.editor.ValidatorDocumentSetupParticipant">
</participant>
</extension>
<extension
point="com.wudsn.ide.lng.compilers">
<compiler
class="com.wudsn.ide.lng.pas.compiler.mp.MadPascalCompiler"
defaultHardware="ATARI8BIT"
defaultParameters="${sourceFilePath} "
helpFilePaths="https://mads.atari8.info/doc/en/index.html"
homePageURL="https://github.com/tebe6502/Mad-Pascal/releases"
id="MP"
language="PAS"
name="%com.wudsn.ide.lng.pas.compiler.mp.MadPascalCompiler.name"
version="1.6.5">
<supportedTarget
target="PASCAL"></supportedTarget>
</compiler>
</extension>
</plugin>

View File

@ -0,0 +1,23 @@
/**
* Copyright (C) 2009 - 2021 <a href="https://www.wudsn.com" target="_top">Peter Dell</a>
*
* This file is part of WUDSN IDE.
*
* WUDSN IDE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* WUDSN IDE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with WUDSN IDE. If not, see <http://www.gnu.org/licenses/>.
*/
package com.wudsn.ide.lng.pas.compiler.mp;
public class MadPascalCompiler {
}

View File

@ -0,0 +1,29 @@
/**
* Copyright (C) 2009 - 2021 <a href="https://www.wudsn.com" target="_top">Peter Dell</a>
*
* This file is part of WUDSN IDE.
*
* WUDSN IDE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* WUDSN IDE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with WUDSN IDE. If not, see <http://www.gnu.org/licenses/>.
*/
package com.wudsn.ide.lng.pas.compiler.mp;
import com.wudsn.ide.lng.editor.LanguageEditor;
public class MadPascalEditor extends LanguageEditor {
/**
* Creation is public. Called by the extension "org.eclipse.ui.editors".
*/
public MadPascalEditor() {
}
}