Skip to content
Snippets Groups Projects
Commit afc4957d authored by Johannes Mey's avatar Johannes Mey
Browse files

Merge branch 'modelica'

parents ebbf18e2 1c56c33e
No related branches found
No related tags found
No related merge requests found
Showing
with 8000 additions and 2 deletions
...@@ -15,7 +15,7 @@ build: ...@@ -15,7 +15,7 @@ build:
- dockered - dockered
stage: build stage: build
script: script:
- ./gradlew --console=plain --build-cache assemble - ./gradlew --console=plain --build-cache assemble -x ":drast:assemble"
cache: cache:
key: "$CI_COMMIT_REF_NAME" key: "$CI_COMMIT_REF_NAME"
policy: push policy: push
...@@ -29,7 +29,7 @@ test: ...@@ -29,7 +29,7 @@ test:
- dockered - dockered
stage: test stage: test
script: script:
- ./gradlew --continue --console=plain check - ./gradlew --continue --console=plain check -x ":drast:check"
cache: cache:
key: "$CI_COMMIT_REF_NAME" key: "$CI_COMMIT_REF_NAME"
policy: pull policy: pull
......
DrAST.cfg
plugins {
id 'java'
id 'application'
}
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
implementation project(':scope4j')
implementation files('../tools/DrAST-1.2.2.jar')
implementation fileTree(dir: "${System.properties['java.home']}", include: '**/jfxrt.jar')
}
run {
mainClassName = 'de.tudresden.inf.st.scope4j.DrAstRunner'
doFirst { environment 'JAVA_TOOL_OPTIONS', '-Dlog4j2.disableJmx=true' }
}
run.dependsOn ':scope4j:jar'
package de.tudresden.inf.st.scope4j;
import drast.Log;
import drast.model.DrAST;
import drast.model.DrASTSettings;
import drast.model.TreeFilter;
import drast.views.gui.DrASTGUI;
import drast.views.gui.GUIData;
import drast.views.gui.controllers.Controller;
import drast.views.gui.graph.GraphView;
import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Rectangle2D;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.ScrollPane;
import javafx.stage.Screen;
import javafx.stage.Stage;
/**
* Extended runner for DrAST
*
* @author jmey - Initial contribution
*/
public class DrAstRunner extends DrASTGUI {
public static void main(String[] args) {
openView();
System.exit(0);
}
private static final GUIData mon = new GUIData();
private static Controller con;
private static boolean guiHasBeenCreated = false;
private static void openView() {
guiHasBeenCreated = true;
DrASTSettings.put(DrASTSettings.PREV_JAR, "../scope4j/scope4j.jar");
DrASTSettings.put(DrASTSettings.PREV_TAIL_ARGS, "--drast");
launch();
con.onApplicationClose();
}
public void setRoot(Object root) {
long timeStart = System.currentTimeMillis();
DrAST newAst = new DrAST(root, TreeFilter.readFilter(con.getFilter()));
Log.info("Filter update: done after %d ms", System.currentTimeMillis() - timeStart);
Platform.runLater(() -> {
mon.reset(newAst);
if (guiHasBeenCreated) {
con.onSetRoot();
} else {
openView();
}
});
}
public void start(Stage stage) throws Exception {
FXMLLoader loader = new FXMLLoader();
Parent rootView = loader.load(this.getClass().getResource("/main.fxml").openStream());
con = loader.getController();
mon.setParentStage(stage);
mon.setController(con);
mon.setDrASTUI(this);
mon.setStage(stage);
GraphView graphview = new GraphView(mon);
graphview.setOnMouseClicked((event) -> graphview.getParent().requestFocus());
mon.setGraphView(graphview);
con.init(mon);
Rectangle2D primaryScreenBounds = Screen.getPrimary().getVisualBounds();
stage.setTitle("Scope4J DrAST 1.2.2");
stage.setScene(new Scene(rootView, primaryScreenBounds.getWidth(), primaryScreenBounds.getHeight() - 100.0D));
stage.show();
ScrollPane center = (ScrollPane)rootView.lookup("#graphViewScrollPane");
center.setContent(graphview);
Platform.runLater(() -> graphview.setPreferredSize((int)center.getWidth(), (int)center.getHeight()));
con.loadPreviousFilter();
}
}
*.jar
!libs/**.jar
!gradle/wrapper/gradle-wrapper.jar
.idea/
.gradle/
build
!src/main/java/org/jmodelica/build/
src/gen-res/
src/gen/
out/
*.class
doc/
logs/
apply plugin: 'jastadd'
apply plugin: 'application'
apply plugin: 'idea'
configurations {
ragdoc
}
dependencies {
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: "2.9.8"
compile group: 'net.sf.beaver', name: 'beaver-rt', version: '0.9.11'
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.11.2'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.11.2'
compile group: 'junit', name: 'junit', version: '4.12'
// testCompile group: 'org.hamcrest', name: 'hamcrest-junit', version: '2.0.0.0'
// testCompile group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.11.2'
jastadd2 "org.jastadd:jastadd:2.3.4"
ragdoc files('libs/rd-builder.jar')
}
buildscript {
repositories.mavenLocal()
repositories.mavenCentral()
dependencies {
classpath group: 'org.jastadd', name: 'jastaddgradle', version: '1.13.2'
}
}
run {
mainClassName = 'org.jmodelica.SimpleMain'
}
// def relastFiles = fileTree('src/main/jastadd/') {
// include '**/*.relast' }.toList().toArray()
// String[] relastArguments = [
// "libs/relast.jar",
// "--grammarName=./src/main/jastadd/mainGen",
// "--useJastAddNames",
// "--listClass=ArrayList",
// "--jastAddList=JastAddList",
// "--file"
// ]
// task preprocess(type: JavaExec) {
// group = 'Build'
// main = "-jar"
// args relastArguments + relastFiles
// inputs.files relastFiles
// outputs.files file("./src/main/jastadd/mainGen.ast"), file("./src/main/jastadd/mainGen.jadd")
// }
jastadd {
configureModuleBuild()
modules file('jastadd_modules')
module = "jmodelica"
// extraJastAddOptions = ['--List=JastAddList']
astPackage = 'org.jmodelica.compiler'
genDir = 'src/gen/java'
buildInfoDir = 'src/gen-res'
parser.name = 'ModelicaParser'
scanner.genDir = "src/gen/java/org/jmodelica/modelica/scanner"
parser.genDir = "src/gen/java/org/jmodelica/modelica/parser"
}
idea.module.generatedSourceDirs += file('src/gen/java')
sourceSets.main {
java {
srcDir 'src/gen/java'
}
}
def ragdocViewSrcData = '../ragdoc-view/src/data/'
task cleanRagdoc(type: Delete) {
group = 'documentation'
delete fileTree(ragdocViewSrcData + '/*')
}
task copyRagdoc(type: Copy, dependsOn: cleanRagdoc) {
group = 'documentation'
description = 'Copy ragdoc json documentation files to ragdoc-viewer'
from 'build/docs/ragdoc'
into ragdocViewSrcData
eachFile { println it.file }
}
// generateAst.dependsOn preprocess
// generateAst.inputs.files file("./src/main/jastadd/mainGen.ast"), file("./src/main/jastadd/mainGen.jadd")
//compileJava.dependsOn jastadd
//
//// always run jastadd
//jastadd.outputs.upToDateWhen {false}
module ("jmodelica") {
jastadd {
basedir "src/main/jastadd"
include "**/*.ast"
include "**/*.jadd"
include "**/*.jrag"
// some stuff, that does not work without other parts of JModelica, like flattened tree, or instance tree
exclude "ignored"
}
java {
basedir "src/"
include "main/java/**/*.java"
include "gen/java/**/*.java"
}
scanner {
include "src/main/parser/Modelica.flex"
}
parser {
include "src/main/parser/Modelica_header.beaver"
include "src/main/parser/Modelica.parser"
}
}
# Things to get compiler working
- copied contents of
- `$JMODLICA_SVN/trunk/Compiler/ModelicaFrontend/src/` into `$THIS_REPO/src/main`
- `$JMODLICA_SVN/trunk/Compiler/ModelicaCompiler/src/` into `$THIS_REPO/src/main`
- `$JMODLICA_SVN/trunk/Compiler/ModelicaFlatTree/src/jastadd/` into `$THIS_REPO/src/main/jastadd/flat`
- use our standard `build.gradle` with package `org.jmodelica`
- for parser and scanner, replace `AST_PACKAGE` with `org.jmodelica.compiler`, and `PARSER_PACKAGE` with `org.jmodelica.parser` (got this information from `build-case.xml`)
- copy `JMODLICA_SVN/trunk//Compiler/ModelicaCompiler/runtime.options` and `JMODLICA_SVN/trunk//Compiler/ModelicaCompiler/module.options` into `$THIS_REPO/src/main/resources/`
- add a new target `genExtraMacro` in the `build.gradle`
- resembled from the `build.xml`, especially from the macro-def `gen-extra-macro`
- manually copied some parts needed for source-analysis, but were defined somewhere else, including:
- replaceMe from FunctionInlining, defined in MiddleEnd
- class Printer, defined in flat
#!/usr/bin/env python3
import os
import subprocess
def main(start_dir):
try:
for directory, subdirectories, files in os.walk(start_dir):
if 'disabled' in subdirectories:
subdirectories.remove('disabled')
for file in files:
filename = directory + '/' + file
# print(filename)
subprocess.check_call(['./gradlew', '-q', 'run', '--args="-q" "' + filename + '"'])
# 1/0
except Exception:
print('Gotcha')
if __name__ == '__main__':
main('src/test/resources/modelica')
/*
Copyright (C) 2014 Modelon AB
This program 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, version 3 of the License.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import org.jmodelica.util.exceptions.CompilerException;
import org.jmodelica.util.logging.Level;
import org.jmodelica.util.logging.StreamingLogger;
import org.jmodelica.util.logging.units.LoggingUnit;
aspect DebugCompiler {
@SuppressWarnings("serial")
public class DebugCompiler extends javax.swing.JFrame {
private javax.swing.JTextArea code;
private javax.swing.JTextField className;
private ModelicaCompiler mc;
private javax.swing.JComboBox target;
private File tempDir;
private boolean deleteAll;
private javax.swing.JTextArea outText;
private javax.swing.JComboBox level;
public DebugCompiler() {
super("Compile Modelica code snippet");
javax.swing.Box page = new javax.swing.Box(javax.swing.BoxLayout.Y_AXIS);
add(page);
page.add(new javax.swing.JLabel("Code:"));
code = new javax.swing.JTextArea("model Test\n\nend Test;", 20, 70);
page.add(new javax.swing.JScrollPane(code));
page.add(new javax.swing.JLabel("Output:"));
outText = new javax.swing.JTextArea("", 20, 70);
page.add(new javax.swing.JScrollPane(outText));
javax.swing.JPanel bottom = new javax.swing.JPanel(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
page.add(bottom);
bottom.add(new javax.swing.JLabel("Log level:"));
level = new javax.swing.JComboBox(Level.values());
level.setSelectedItem(Level.DEBUG);
bottom.add(level);
bottom.add(new javax.swing.JLabel("Target:"));
target = new javax.swing.JComboBox(ModelicaCompiler.TargetObject.values());
bottom.add(target);
bottom.add(new javax.swing.JLabel("Class to compile:"));
className = new javax.swing.JTextField("Test", 20);
bottom.add(className);
javax.swing.JButton compile = new javax.swing.JButton("Compile");
bottom.add(compile);
compile.addActionListener(new CompileListener());
setDefaultCloseOperation(EXIT_ON_CLOSE);
pack();
mc = new ModelicaCompiler(ModelicaCompiler.createOptions());
tempDir = getTempDir();
mc.setTempFileDir(tempDir);
}
public File getTempDir() {
try {
File tempDir = File.createTempFile("org.jmodelica.util.", "");
tempDir.delete();
if (tempDir.mkdir()) {
tempDir.deleteOnExit();
deleteAll = true;
return tempDir;
}
} catch (IOException e) {
} catch (SecurityException e) {
}
deleteAll = false;
return new File(System.getProperty("java.io.tmpdir"));
}
public static void main(String[] args) {
new DebugCompiler().setVisible(true);
}
public class CompileListener implements java.awt.event.ActionListener {
public void actionPerformed(java.awt.event.ActionEvent e) {
new CompilationThread(className.getText(), code.getText()).start();
}
}
public class CompilationThread extends Thread {
private String name;
private String code;
public CompilationThread(String name, String code) {
this.name = name;
this.code = code;
}
public void run() {
File file = new File(tempDir, name + ".mo");
Level lv = (Level) level.getSelectedItem();
OutputHandler out = new OutputHandler(outText, lv);
outText.setText("");
try {
PrintStream fs = new PrintStream(file);
fs.println(code);
fs.close();
mc.setLogger(out);
ModelicaCompiler.TargetObject targ = (ModelicaCompiler.TargetObject) target.getSelectedItem();
mc.compileModel(new String[] { file.getAbsolutePath() }, name, targ, null, null);
} catch (Exception ex) {
out.writeException(ex);
return;
} finally {
try {
if (deleteAll)
for (File f : tempDir.listFiles())
f.delete();
else
file.delete();
} catch (Exception ex) {}
}
out.info("*** Compilation sucessful. ***");
}
}
public class OutputHandler extends ModelicaLogger {
private javax.swing.JTextArea target;
public OutputHandler(javax.swing.JTextArea target, Level level) {
super(level);
this.target = target;
}
public void reset() {
target.setText("");
}
protected void writeException(Exception ex) {
if (ex instanceof CompilerException) {
do_write(ex.toString());
} else {
ByteArrayOutputStream buf = new ByteArrayOutputStream(512);
ex.printStackTrace(new PrintStream(buf));
do_write(buf.toString());
}
}
@Override
public void close() {
}
@Override
protected void write(Level level, Level alreadySentLevel, LoggingUnit unit) {
do_write(unit.print(level));
}
protected void do_write(String message) {
target.append(message + "\n");
}
}
}
}
/*
Copyright (C) 2014 Modelon AB
This program 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, version 3 of the License.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
abstract BaseNode;
abstract Root : BaseNode;
/*
Copyright (C) 2009-2018 Modelon AB
This program 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, version 3 of the License.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
SrcBadDefinition: SrcStoredDefinition;
SrcBadClassDecl: SrcClassDecl;
SrcBadElement: SrcElement;
SrcBadArgument: SrcArgument;
SrcBadStatement: SrcStatement;
\ No newline at end of file
/*
Copyright (C) 2009 Modelon AB
This program 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, version 3 of the License.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \mainpage API documentation of the JModelica.org Modelica Front-end
*
* The API documentation of the Modelica %compiler front-end is yet rudimentary.
* Also, the APIs for the Java classes contains several methods that are
* part of the internal JastAdd run-time system - these methods are not intended
* to be used by the user.
*
* We are currently working together with the JastAdd team to develop a
* documentation system where internal methods are hidden and where the user
* API is exposed.
*
* The Modelica %compiler is organized into a number of different packages:
* <ul>
* <li> org.jmodelica.modelica.parser containing parsers for Modelica
* and Flat Modelica code.</li>
* <li> org.jmodelica.modelica.compiler contains the actual %compiler, including
* the classes used to construct the Abstract Syntax Trees (ASTs) and the
* %compiler driver class ModelicaCompiler.</li>
* <li> org.jmodelica.util contains some helper classes which are independent
* of the AST classes.</li>
* </ul>
*
* Notice that the Java classes are not intended to be edited manually (with
* the exception of the classes in org.jmodelica.util), but are rather
* automatically generated by the JastAdd tool. In order to extend or
* modify the functionality of the %compiler, edit the .%ast, .jrag and .jadd
* files.
*
*/
// Modelica abstract grammar
/**
* \package org.jmodelica.ast Package containing all AST classes.
*/
abstract SrcBaseNode : BaseNode;
/**
* A class representing the root node of a source AST.
*/
SourceRoot : Root ::= Program;
Program : SrcBaseNode ::=
UnstructuredEntity:SrcStoredDefinition*
/SrcUnknownClassDecl/
/UnknownComponent:SrcComponentClause/
/EnumBaseDecl:SrcEnumClassDecl/
/PredefinedType:SrcBaseClassDecl*/
/BuiltInType:SrcClassDecl*/
/BuiltInFunction:SrcBaseClassDecl*/
/SrcLibNode*/
/AnonymousClass:SrcBaseClassDecl*/;
SrcStoredDefinition : SrcBaseNode ::= [SrcWithin] SrcClassDecl*;
SrcWithin : SrcBaseNode ::= [PackageName:SrcAccess];
abstract SrcClassDecl : SrcElement ::= Name:SrcIdDecl;
abstract SrcBaseClassDecl : SrcClassDecl ::= <Encapsulated:boolean>
<Partial:boolean>
SrcRestriction
<Redeclare:boolean>
<Final:boolean>
<Inner:boolean>
<Outer:boolean>
<Replaceable:boolean>
[SrcConstrainingClause]
[ConstrainingClauseComment:SrcComment];
SrcUnknownClassDecl : SrcFullClassDecl;
SrcFullClassDecl : SrcBaseClassDecl ::= [SrcStringComment]
SrcClause*
[SrcExternalClause]
[SrcAnnotation]
SrcEndDecl;
SrcLibClassDecl : SrcFullClassDecl ::= SrcLibNode*;
SrcLibNode : SrcClassDecl ::= <FileName:String>
<Structured:boolean>
<Version:String>
<Reason:SrcLibNode.LoadReason>
/SrcStoredDefinition/;
SrcShortClassDecl : SrcBaseClassDecl ::= SrcExtendsClauseShortClass;
SrcExtendsClauseShortClass : SrcExtendsClause ::= [SrcTypePrefixFlow]
[SrcTypePrefixVariability]
[SrcTypePrefixInputOutput]
[SrcArraySubscripts]
SrcComment;
SrcExtendClassDecl : SrcFullClassDecl ::= SrcInlineExtendsClause;
SrcPrimitiveClassDecl : SrcFullClassDecl;
SrcRealClassDecl : SrcPrimitiveClassDecl;
SrcIntegerClassDecl : SrcPrimitiveClassDecl;
SrcBooleanClassDecl : SrcPrimitiveClassDecl;
SrcStringClassDecl : SrcPrimitiveClassDecl;
SrcEnumClassDecl : SrcPrimitiveClassDecl;
SrcEnumLiteralDecl : SrcComponentDecl;
SrcBuiltInClassDecl : SrcClassDecl;
SrcConstrainingClause : SrcBaseNode ::= SrcAccess [SrcClassModification];
abstract SrcRestriction : SrcBaseNode;
SrcModel : SrcRestriction;
SrcBlock : SrcRestriction;
SrcClass : SrcRestriction;
SrcConnector : SrcRestriction;
SrcExpandableConnector : SrcConnector;
SrcType : SrcRestriction;
SrcPackage : SrcRestriction;
SrcFunction : SrcRestriction;
SrcRecord : SrcRestriction;
SrcOperatorRecord : SrcRecord;
SrcOperator : SrcRestriction;
SrcOperatorFunction : SrcFunction;
SrcExternalClause : SrcBaseNode ::= [SrcExternalLanguage]
[SrcExternalFunctionCall]
[SrcAnnotation];
SrcExternalFunctionCall : SrcBaseNode ::= [ReturnVar:SrcAccess] FunctionName:SrcIdDecl Arg:SrcExp*;
SrcExternalLanguage : SrcBaseNode ::= <Language>;
abstract SrcClause : SrcBaseNode;
abstract SrcElementList : SrcClause ::= SrcElement*;
SrcPublicElementList : SrcElementList;
SrcDefaultElementList : SrcPublicElementList;
SrcProtectedElementList : SrcElementList;
SrcEquationClause : SrcClause ::= SrcAbstractEquation*;
SrcInitialEquationClause : SrcEquationClause;
SrcAlgorithm : SrcClause ::= SrcStatement*;
SrcInitialAlgorithm : SrcAlgorithm;
abstract SrcElement : SrcBaseNode;
SrcExtendsClause : SrcElement ::= Super:SrcAccess [SrcClassModification] [SrcAnnotation];
SrcInlineExtendsClause : SrcExtendsClause;
abstract SrcImportClause : SrcElement ::= PackageName:SrcAccess SrcComment;
SrcImportClauseQualified : SrcImportClause;
SrcImportClauseUnqualified : SrcImportClause;
SrcImportClauseRename : SrcImportClause ::= SrcIdDecl;
SrcComponentClause : SrcElement ::= <Redeclare:boolean>
<Final:boolean>
<Inner:boolean>
<Outer:boolean>
<Replaceable:boolean>
[SrcTypePrefixFlow]
[SrcTypePrefixVariability]
[SrcTypePrefixInputOutput]
ClassName:SrcAccess
[TypeArraySubscripts:SrcArraySubscripts]
SrcComponentDecl*
[SrcConstrainingClause]
SrcComment;
SrcEnumComponentClause : SrcComponentClause;
SrcComponentDecl : SrcBaseNode ::= Name:SrcIdDecl
[VarArraySubscripts:SrcArraySubscripts]
[SrcModification]
[SrcConditionalAttribute]
SrcComment;
SrcUnknownComponentDecl : SrcComponentDecl;
abstract SrcTypePrefix : SrcBaseNode;
abstract SrcTypePrefixFlow : SrcTypePrefix;
SrcFlow : SrcTypePrefixFlow;
SrcStream : SrcTypePrefixFlow;
abstract SrcTypePrefixVariability : SrcTypePrefix;
SrcContinuous : SrcTypePrefixVariability;
SrcDiscrete : SrcTypePrefixVariability;
SrcParameter : SrcTypePrefixVariability;
SrcIndexParameter : SrcParameter;
SrcConstant : SrcTypePrefixVariability;
abstract SrcTypePrefixInputOutput : SrcTypePrefix;
SrcInput : SrcTypePrefixInputOutput;
SrcOutput : SrcTypePrefixInputOutput;
SrcComment : SrcBaseNode ::= [SrcStringComment] [SrcAnnotation];
SrcStringComment : SrcBaseNode ::= SrcExp;
// Annotations and modifications
SrcConditionalAttribute : SrcBaseNode ::= SrcExp;
abstract SrcModification : SrcBaseNode;
SrcCompleteModification : SrcModification ::= SrcClassModification [SrcValueModification];
SrcValueModification : SrcModification ::= SrcExp;
SrcDummyModification : SrcValueModification;
SrcClassModification : SrcModification ::= SrcArgument*;
abstract SrcArgument : SrcModification ::= <Each:boolean> <Final:boolean>;
abstract SrcNamedModification : SrcArgument ::= Name:SrcAccess;
abstract SrcElementModification : SrcNamedModification ::= [SrcModification] SrcComment;
SrcComponentModification : SrcElementModification;
abstract SrcElementRedeclare : SrcNamedModification;
SrcClassRedeclare : SrcElementRedeclare ::= SrcBaseClassDecl;
SrcComponentRedeclare : SrcElementRedeclare ::= SrcComponentClause;
abstract SrcAnnotation : SrcBaseNode;
SrcParseAnnotation : SrcAnnotation ::= SrcClassModification;
abstract SrcAbstractExp : SrcBaseNode;
abstract SrcExp : SrcAbstractExp;
abstract SrcAbstractEquation : SrcBaseNode ::= SrcComment;
SrcEquation : SrcAbstractEquation ::= Left:SrcExp Right:SrcExp;
SrcConnectClause : SrcAbstractEquation ::= Connector1:SrcAccess Connector2:SrcAccess;
abstract SrcIfWhenElseEquation : SrcAbstractEquation ::= SrcAbstractEquation*;
abstract SrcIfWhenEquation : SrcIfWhenElseEquation ::= Test:SrcExp [Else:SrcIfWhenElseEquation];
SrcIfEquation : SrcIfWhenEquation;
SrcWhenEquation : SrcIfWhenEquation;
SrcElseEquation : SrcIfWhenElseEquation;
SrcForClauseE : SrcAbstractEquation ::= SrcForIndex* SrcAbstractEquation*;
SrcFunctionCallEquation : SrcAbstractEquation ::= Left:SrcFunctionCallLeft* Call:SrcFunctionCall;
SrcFunctionCallLeft : SrcBaseNode ::= [SrcAccess];
SrcForIndex : SrcComponentClause ::= [SrcExp];
SrcForIndexDecl : SrcComponentDecl;
abstract SrcStatement : SrcBaseNode ::= SrcComment;
SrcAssignStmt : SrcStatement ::= Left:SrcAccess Right:SrcExp;
SrcFunctionCallStmt : SrcStatement ::= Left:SrcFunctionCallLeft* SrcFunctionCall;
SrcBreakStmt : SrcStatement;
SrcReturnStmt : SrcStatement;
abstract SrcIfWhenStmt : SrcStatement ::= SrcIfWhenClause*;
SrcIfStmt : SrcIfWhenStmt ::= [SrcElseClause];
SrcWhenStmt : SrcIfWhenStmt;
SrcElseClause : SrcBaseNode ::= Stmt:SrcStatement*;
abstract SrcIfWhenClause : SrcBaseNode ::= Test:SrcExp SrcStatement*;
SrcIfClause : SrcIfWhenClause;
SrcWhenClause : SrcIfWhenClause;
SrcForStmt : SrcStatement ::= SrcForIndex* SrcStatement*;
SrcWhileStmt : SrcStatement ::= Test:SrcExp SrcWhileStmt:SrcStatement*;
SrcParExp : SrcExp ::= SrcExp;
SrcIfExp : SrcExp ::= SrcIfExp:SrcExp ThenExp:SrcExp ElseExp:SrcExp;
abstract SrcBinExp : SrcExp ::= Left:SrcExp Right:SrcExp;
abstract SrcArtmBinExp : SrcBinExp;
SrcDotAddExp : SrcArtmBinExp;
SrcDotSubExp : SrcArtmBinExp;
SrcDotMulExp : SrcArtmBinExp;
SrcDotDivExp : SrcArtmBinExp;
SrcDotPowExp : SrcArtmBinExp; // Easy to make parser take care of this: should be a Primary
SrcAddExp : SrcDotAddExp;
SrcSubExp : SrcDotSubExp;
SrcMulExp : SrcDotMulExp;
SrcDivExp : SrcDotDivExp;
SrcPowExp : SrcDotPowExp; // Easy to make parser take care of this: should be a Primary
SrcNegExp : SrcExp ::= SrcExp;
SrcRealLitExp : SrcExp ::= <UNSIGNED_NUMBER>;
SrcIntegerLitExp : SrcExp ::= <UNSIGNED_INTEGER>;
SrcStringLitExp : SrcExp ::= <STRING>;
abstract SrcBooleanLitExp : SrcExp;
SrcBooleanLitExpTrue : SrcBooleanLitExp;
SrcBooleanLitExpFalse : SrcBooleanLitExp;
SrcFunctionCall : SrcExp ::= Name:SrcAccess [SrcFunctionArguments];
SrcPartialFunctionCall : SrcFunctionCall;
SrcFunctionArguments : SrcBaseNode::= SrcExp* SrcNamedArgument*;
SrcNamedArgument : SrcBaseNode::= Name:SrcAccess SrcExp;
SrcIterExp : SrcExp ::= SrcExp SrcForIndex*;
SrcRangeExp : SrcExp ::= SrcExp*;
abstract SrcLogBinExp : SrcBinExp;
SrcLtExp : SrcLogBinExp;
SrcLeqExp : SrcLogBinExp;
SrcGtExp : SrcLogBinExp;
SrcGeqExp : SrcLogBinExp;
SrcEqExp : SrcLogBinExp;
SrcNeqExp : SrcLogBinExp;
SrcNotExp : SrcExp ::= SrcExp;
SrcOrExp : SrcLogBinExp;
SrcAndExp : SrcLogBinExp;
SrcIdDecl : SrcBaseNode ::= <ID>;
SrcDerExp : SrcExp ::= SrcExp;
SrcAccessExp : SrcExp ::= SrcAccess;
abstract SrcAccess : SrcBaseNode;
SrcDot : SrcAccess ::= SrcAccess*;
SrcGlobalAccess : SrcAccess ::= SrcAccess;
SrcNamedAccess : SrcAccess ::= <ID>;
SrcArrayAccess : SrcNamedAccess ::= SrcArraySubscripts;
SrcArrayConstructor : SrcExp ::= SrcFunctionArguments;
SrcMatrix : SrcExp ::= Row:SrcMatrixRow*;
SrcMatrixRow : SrcExp ::= SrcExp*;
SrcArraySubscripts : SrcBaseNode ::= SrcSubscript*;
abstract SrcSubscript : SrcBaseNode;
SrcColonSubscript : SrcSubscript;
SrcExpSubscript : SrcSubscript ::= SrcExp;
SrcTimeExp : SrcExp;
SrcEndExp : SrcExp;
SrcEndDecl : SrcBaseNode ::= <EndID:String>;
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/*
Copyright (C) 2015 Modelon AB
This program 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, version 3 of the License.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
import java.util.Collections;
import java.util.Iterator;
import org.jmodelica.util.ErrorCheckType;
aspect ErrorClasses {
syn boolean ASTNode.isError() = false;
eq SrcBadDefinition.isError() = true;
eq SrcBadClassDecl.isError() = true;
eq SrcBadElement.isError() = true;
eq SrcBadArgument.isError() = true;
eq SrcBadStatement.isError() = true;
public InstModification SrcBadArgument.newInstModification() {
return null;
}
public FStatement SrcBadStatement.instantiateStatement() {
return null;
}
// Make iterator empty to prevent traversials from throwing null pointer exceptions.
public Iterator<ASTNode> SrcBadDefinition.iterator() {
return Collections.<ASTNode>emptyList().iterator();
}
public Iterator<ASTNode> SrcBadClassDecl.iterator() {
return Collections.<ASTNode>emptyList().iterator();
}
public Iterator<ASTNode> SrcBadElement.iterator() {
return Collections.<ASTNode>emptyList().iterator();
}
public Iterator<ASTNode> SrcBadArgument.iterator() {
return Collections.<ASTNode>emptyList().iterator();
}
public Iterator<ASTNode> SrcBadStatement.iterator() {
return Collections.<ASTNode>emptyList().iterator();
}
// Common information to save in bad nodes
public class BadNodeInfo {
private Problem problemToReport;
private ASTNode node;
public BadNodeInfo(ASTNode n) {
node = n;
problemToReport = null;
}
public void reportProblem(Problem p) {
problemToReport = p;
}
public void collectErrors(ErrorCheckType checkType) {
if (problemToReport != null) {
// report problem (missing suupport in error handler
}
}
}
private BadNodeInfo SrcBadDefinition.badNodeInfo = null;
private BadNodeInfo SrcBadClassDecl.badNodeInfo = null;
private BadNodeInfo SrcBadElement.badNodeInfo = null;
private BadNodeInfo SrcBadArgument.badNodeInfo = null;
private BadNodeInfo SrcBadStatement.badNodeInfo = null;
public BadNodeInfo SrcBadDefinition.badInfo() {
if (badNodeInfo == null)
badNodeInfo = new BadNodeInfo(this);
return badNodeInfo;
}
public BadNodeInfo SrcBadClassDecl.badInfo() {
if (badNodeInfo == null)
badNodeInfo = new BadNodeInfo(this);
return badNodeInfo;
}
public BadNodeInfo SrcBadElement.badInfo() {
if (badNodeInfo == null)
badNodeInfo = new BadNodeInfo(this);
return badNodeInfo;
}
public BadNodeInfo SrcBadArgument.badInfo() {
if (badNodeInfo == null)
badNodeInfo = new BadNodeInfo(this);
return badNodeInfo;
}
public BadNodeInfo SrcBadStatement.badInfo() {
if (badNodeInfo == null)
badNodeInfo = new BadNodeInfo(this);
return badNodeInfo;
}
// Delegate error reporting to SrcBadInfoNode
public void SrcBadDefinition.collectErrors(ErrorCheckType checkType) {
if (badNodeInfo != null)
badNodeInfo.collectErrors(checkType);
super.collectErrors(checkType);
}
public void SrcBadClassDecl.collectErrors(ErrorCheckType checkType) {
if (badNodeInfo != null)
badNodeInfo.collectErrors(checkType);
super.collectErrors(checkType);
}
public void SrcBadElement.collectErrors(ErrorCheckType checkType) {
if (badNodeInfo != null)
badNodeInfo.collectErrors(checkType);
super.collectErrors(checkType);
}
public void SrcBadArgument.collectErrors(ErrorCheckType checkType) {
if (badNodeInfo != null)
badNodeInfo.collectErrors(checkType);
super.collectErrors(checkType);
}
public void SrcBadStatement.collectErrors(ErrorCheckType checkType) {
if (badNodeInfo != null)
badNodeInfo.collectErrors(checkType);
super.collectErrors(checkType);
}
public SrcBadClassDecl.SrcBadClassDecl(String name) {
super(new SrcIdDecl(name));
}
}
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment