Skip to content
Snippets Groups Projects
Commit 0927b584 authored by René Schöne's avatar René Schöne
Browse files

Replace jmodelica submodule with real files.

parent 76b16f29
Branches
No related tags found
No related merge requests found
Showing
with 14382 additions and 4 deletions
[submodule "extendj"]
path = extendj
url = https://bitbucket.org/extendj/extendj.git
[submodule "jmodelica"]
path = jmodelica
url = git@git-st.inf.tu-dresden.de:jastadd/jmodelica.git
Subproject commit e43b28eb598eaa4a9330fbce00512321a26db32f
*.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.
/*
Copyright (C) 2010 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 org.jmodelica.util.ErrorCheckType;
import org.jmodelica.util.problemHandling.SimpleProblemProducer;
import org.jmodelica.util.problemHandling.SimpleWarningProducer;
import org.jmodelica.util.problemHandling.SimpleErrorProducer;
import org.jmodelica.util.problemHandling.ComplianceFMUOnlyProducer;
aspect ComplianceCheck {
/**
* Check for code that is not allowed in its current context.
*
* Examples would be checking that classes follow the requirements of
* their restriction.
*/
public void ASTNode.complianceCheck(ErrorCheckType checkType) {}
public abstract class ErrorChecker {
public static class ComplianceChecker extends ErrorChecker {
public ComplianceChecker() {
super("ComplianceCheck");
}
@Override
public void check(ASTNode node, ErrorCheckType checkType) {
node.complianceCheck(checkType);
}
}
}
private static ErrorChecker ASTNode.COMPLIANCE_CHECKER = addErrorChecker(new ErrorChecker.ComplianceChecker());
public static final SimpleProblemProducer ASTNode.ONLY_FMU_IF_STATEMENTS =
new ComplianceFMUOnlyProducer("ONLY_FMU_IF_STATEMENTS", "Using if statements is");
public void FIfWhenClause.complianceCheck(ErrorCheckType checkType) {
super.complianceCheck(checkType);
if (!getTest().variability().parameterOrLess())
ONLY_FMU_IF_STATEMENTS.invoke(this);
}
public static final SimpleProblemProducer ASTNode.ONLY_FMU_WHILE_STATEMENTS =
new ComplianceFMUOnlyProducer("ONLY_FMU_WHILE_STATEMENTS", "Using while statements is");
public void FWhileStmt.complianceCheck(ErrorCheckType checkType) {
super.complianceCheck(checkType);
if (!getTest().variability().parameterOrLess())
ONLY_FMU_WHILE_STATEMENTS.invoke(this);
}
public static final SimpleProblemProducer ASTNode.UNSUPPORTED_EVENT_GENERATING_EXPRESSION_IN_WHILE_STATEMENT =
new SimpleErrorProducer("UNSUPPORTED_EVENT_GENERATING_EXPRESSION_IN_WHILE_STATEMENT", ProblemKind.COMPLIANCE, "Event generating expressions are not supported in while statements");
public void FRelExp.complianceCheck(ErrorCheckType checkType) {
super.complianceCheck(checkType);
if (!inFunction() && generatesEvent() && inWhile())
UNSUPPORTED_EVENT_GENERATING_EXPRESSION_IN_WHILE_STATEMENT.invoke(this);
}
public static final SimpleProblemProducer ASTNode.ONLY_FMU_FUNCTION_LIKE_OPERATOR =
new ComplianceFMUOnlyProducer("ONLY_FMU_FUNCTION_LIKE_OPERATOR", "The %s() function-like operator is");
public void FEventGenExp.complianceCheck(ErrorCheckType checkType) {
super.complianceCheck(checkType);
ONLY_FMU_FUNCTION_LIKE_OPERATOR.invoke(this, name());
if (!inFunction() && generatesEvent() && inWhile())
UNSUPPORTED_EVENT_GENERATING_EXPRESSION_IN_WHILE_STATEMENT.invoke(this);
}
inh boolean FRelExp.inWhile();
inh boolean FEventGenExp.inWhile();
eq FWhileStmt.getChild().inWhile() = true;
eq Root.getChild().inWhile() = false;
eq FAlgorithm.getChild().inWhile() = false;
public static final SimpleProblemProducer ASTNode.ONLY_FMU_NON_FIXED_RECORD_ARRAY_INDEX =
new ComplianceFMUOnlyProducer("ONLY_FMU_NON_FIXED_RECORD_ARRAY_INDEX", "Using arrays of records with indices of higher than parameter variability is");
public static final SimpleProblemProducer ASTNode.EXTERNAL_OBJECT_CONSTANT_IN_COMPOSITE =
new SimpleErrorProducer("EXTERNAL_OBJECT_CONSTANT_IN_COMPOSITE", ProblemKind.COMPLIANCE, "Access to external object constants in arrays or records is not supported");
public void InstAccess.complianceCheck(ErrorCheckType checkType) {
super.complianceCheck(checkType);
InstComponentDecl decl = myInstComponentDecl();
if (decl.isRecord() && hasFArraySubscripts() && inFunction() &&
!getFArraySubscripts().variability().parameterOrLess()) {
ONLY_FMU_NON_FIXED_RECORD_ARRAY_INDEX.invoke(this);
}
if (decl.isExternalObject() && decl.isConstant() && (decl.inRecord() || decl.isArray())) {
EXTERNAL_OBJECT_CONSTANT_IN_COMPOSITE.invoke(this);
}
}
public static final SimpleProblemProducer ASTNode.ONLY_FMU_WHEN_EQUATIONS =
new ComplianceFMUOnlyProducer("ONLY_FMU_WHEN_EQUATIONS", "When equations are");
public void FWhenEquation.complianceCheck(ErrorCheckType checkType) {
ONLY_FMU_WHEN_EQUATIONS.invoke(this);
}
@Deprecated
public void ASTNode.complianceOnlyFMU(String message) {
if (!myOptions().getBooleanOption("generate_ode"))
compliance(message + " currently only supported when compiling FMUs");
}
public static final SimpleProblemProducer ASTNode.UNSUPPORTED_EQUATION_TYPE =
new SimpleErrorProducer("UNSUPPORTED_EQUATION_TYPE", ProblemKind.COMPLIANCE, "Unsupported equation type");
public void FUnsupportedEquation.collectErrors(ErrorCheckType checkType) {
UNSUPPORTED_EQUATION_TYPE.invoke(this);
}
public static final SimpleProblemProducer ASTNode.UNSUPPORTED_EXPRESSION_TYPE =
new SimpleErrorProducer("UNSUPPORTED_EXPRESSION_TYPE", ProblemKind.COMPLIANCE, "Unsupported expression type");
public void FUnsupportedExp.collectErrors(ErrorCheckType checkType) {
UNSUPPORTED_EXPRESSION_TYPE.invoke(this);
}
public static final SimpleProblemProducer ASTNode.UNSUPPORTED_FUNCTION_LIKE_OPERATOR =
new SimpleErrorProducer("UNSUPPORTED_FUNCTION_LIKE_OPERATOR", ProblemKind.COMPLIANCE, "The %s() function-like operator is not supported");
public void FUnsupportedBuiltIn.complianceCheck(ErrorCheckType checkType) {
UNSUPPORTED_FUNCTION_LIKE_OPERATOR.invoke(this, getName());
}
public void FSampleExp.complianceCheck(ErrorCheckType checkType) {
ONLY_FMU_FUNCTION_LIKE_OPERATOR.invoke(this, "sample");
}
public void InstPreExp.complianceCheck(ErrorCheckType checkType) {
ONLY_FMU_FUNCTION_LIKE_OPERATOR.invoke(this, "pre");
}
public void FEdgeExp.complianceCheck(ErrorCheckType checkType) {
ONLY_FMU_FUNCTION_LIKE_OPERATOR.invoke(this, "edge");
}
public void FChangeExp.complianceCheck(ErrorCheckType checkType) {
ONLY_FMU_FUNCTION_LIKE_OPERATOR.invoke(this, "change");
}
public void FInitialExp.complianceCheck(ErrorCheckType checkType) {
ONLY_FMU_FUNCTION_LIKE_OPERATOR.invoke(this, "initial");
}
public void FSignExp.complianceCheck(ErrorCheckType checkType) {
ONLY_FMU_FUNCTION_LIKE_OPERATOR.invoke(this, "sign");
}
public void FSemiLinearExp.complianceCheck(ErrorCheckType checkType) {
ONLY_FMU_FUNCTION_LIKE_OPERATOR.invoke(this, "semiLinear");
}
public static final SimpleProblemProducer ASTNode.DEPRECATED_DECOUPLE =
new SimpleWarningProducer("DEPRECATED_DECOUPLE", ProblemKind.SEMANTIC, "The Subtask.decouple() function-like operator is removed as of Modelica version 3.2r2");
public void FDecouple.complianceCheck(ErrorCheckType checkType) {
DEPRECATED_DECOUPLE.invoke(this);
}
public static final SimpleProblemProducer ASTNode.DEPRECATED_CARDINALITY =
new SimpleWarningProducer("DEPRECATED_CARDINALITY", ProblemKind.SEMANTIC, "The cardinality() function-like operator is deprecated, and will be removed in a future version of Modelica");
public static final SimpleProblemProducer ASTNode.INCORRECT_USE_OF_CARDINALITY =
new SimpleErrorProducer("INCORRECT_USE_OF_CARDINALITY", ProblemKind.COMPLIANCE, "The cardinality() function-like operator is only supported in asserts and in the tests of if clauses that do not contain connect()");
public void FCardinality.complianceCheck(ErrorCheckType checkType) {
DEPRECATED_CARDINALITY.invoke(this);
if (!inAssert() && !inIfTestWithoutConnect())
INCORRECT_USE_OF_CARDINALITY.invoke(this);
}
public void FDelayExp.complianceCheck(ErrorCheckType checkType) {
ONLY_FMU_FUNCTION_LIKE_OPERATOR.invoke(this, "delay");
}
public static final SimpleProblemProducer ASTNode.INCORRECT_USE_OF_SPATIAL_DISTRIBUTION =
new SimpleErrorProducer("INCORRECT_USE_OF_SPATIAL_DISTRIBUTION", ProblemKind.COMPLIANCE, "The spatialDistribution() function-like operator is not supported vectorized in function call equations");
public void FSpatialDistExp.complianceCheck(ErrorCheckType checkType) {
ONLY_FMU_FUNCTION_LIKE_OPERATOR.invoke(this, "spatialDistribution");
FAbstractEquation equation = myFEquation();
if (isArray() && equation != null && equation instanceof FFunctionCallEquation) {
INCORRECT_USE_OF_SPATIAL_DISTRIBUTION.invoke(this);
}
}
inh boolean FCardinality.inAssert();
eq FAssert.getChild().inAssert() = true;
eq Root.getChild().inAssert() = false;
eq InstNode.getChild().inAssert() = false;
inh boolean FCardinality.inIfTestWithoutConnect();
eq FIfEquation.getTest().inIfTestWithoutConnect() = !containsConnect();
eq Root.getChild().inIfTestWithoutConnect() = false;
eq InstNode.getChild().inIfTestWithoutConnect() = false;
syn boolean FAbstractEquation.containsConnect() = false;
eq FConnectClause.containsConnect() = true;
eq FForClauseE.containsConnect() = containsConnect(getFAbstractEquations());
eq FIfWhenElseEquation.containsConnect() = containsConnect(getFAbstractEquations());
eq FIfWhenEquation.containsConnect() =
super.containsConnect() || (hasElse() && getElse().containsConnect());
public static boolean FAbstractEquation.containsConnect(List<FAbstractEquation> eqns) {
for (FAbstractEquation eqn : eqns)
if (eqn.containsConnect())
return true;
return false;
}
public static final SimpleProblemProducer ASTNode.UNSUPPORTED_IN_FUNCTION_UNKNOWN_SIZE_OPERATOR =
new SimpleErrorProducer("UNSUPPORTED_IN_FUNCTION_UNKNOWN_SIZE_OPERATOR", ProblemKind.COMPLIANCE, "Unknown sizes in operator %s is not supported in functions");
public void FUnaryBuiltIn.complianceCheck(ErrorCheckType checkType) {
super.complianceCheck(checkType);
if (!unknownSizeSupported() && inFunction() && getFExp().size().isUnknown()) {
UNSUPPORTED_IN_FUNCTION_UNKNOWN_SIZE_OPERATOR.invoke(this, name() + "()");
}
}
syn boolean FUnaryBuiltIn.unknownSizeSupported() = true;
eq FSymmetric.unknownSizeSupported() = false;
public static final SimpleProblemProducer ASTNode.UNSUPPORTED_NON_FIXED_FOR_INDEX =
new SimpleErrorProducer("UNSUPPORTED_NON_FIXED_FOR_INDEX", ProblemKind.COMPLIANCE, "For index with higher than parameter variability is not supported in equations and algorithms");
public void InstForIndexWithExp.complianceCheck(ErrorCheckType checkType) {
super.complianceCheck(checkType);
if (!getFExp().variability().parameterOrLess() && !inFunction()) {
UNSUPPORTED_NON_FIXED_FOR_INDEX.invoke(this);
}
}
public void InstForIndex.contentCheck(ErrorCheckType checkType) {
}
public void FPowExp.complianceCheck(ErrorCheckType checkType) {
super.complianceCheck(checkType);
if (inFunction() && getLeft().size().isUnknown()) {
UNSUPPORTED_IN_FUNCTION_UNKNOWN_SIZE_OPERATOR.invoke(this, "^");
}
}
public static final SimpleProblemProducer ASTNode.UNSUPPORTED_FUNCTION_LIKE_OPERATOR_IGNORED =
new SimpleWarningProducer("UNSUPPORTED_FUNCTION_LIKE_OPERATOR_IGNORED", ProblemKind.COMPLIANCE, "The %s() function-like operator is not supported, and is currently ignored");
public void FIgnoredBuiltIn.complianceCheck(ErrorCheckType checkType) {
UNSUPPORTED_FUNCTION_LIKE_OPERATOR_IGNORED.invoke(this, name());
}
public static final SimpleProblemProducer ASTNode.UNSUPPORTED_FUNCTION_LIKE_OPERATOR_EVAL_FALSE =
new SimpleWarningProducer("UNSUPPORTED_FUNCTION_LIKE_OPERATOR_EVAL_FALSE", ProblemKind.COMPLIANCE, "The %s() function-like operator is not supported, and is currently evaluated to false");
public void FTerminalExp.complianceCheck(ErrorCheckType checkType) {
UNSUPPORTED_FUNCTION_LIKE_OPERATOR_EVAL_FALSE.invoke(this, name());
}
public void FTerminate.complianceCheck(ErrorCheckType checkType) {
ONLY_FMU_FUNCTION_LIKE_OPERATOR.invoke(this, "terminate");
}
public void FReinit.complianceCheck(ErrorCheckType checkType) {
ONLY_FMU_FUNCTION_LIKE_OPERATOR.invoke(this, "reinit");
}
public static final SimpleProblemProducer ASTNode.UNSUPPORTED_NON_FIXED_STRING_ARGUMENT =
new SimpleErrorProducer("UNSUPPORTED_NON_FIXED_STRING_ARGUMENT", ProblemKind.COMPLIANCE, "%s with higher than parameter variability is not supported");
public void FStringExp.complianceCheck(ErrorCheckType checkType) {
super.complianceCheck(checkType);
boolean func = inFunction();
if (!func && hasMinimumLength()) {
getMinimumLength().markAsStructuralParameter(checkType);
if (!getMinimumLength().variability().parameterOrLess())
UNSUPPORTED_NON_FIXED_STRING_ARGUMENT.invoke(getMinimumLength(), "minimumLength");
}
if (!func && hasLeftJustified()) {
getLeftJustified().markAsStructuralParameter(checkType);
if (!getLeftJustified().variability().parameterOrLess())
UNSUPPORTED_NON_FIXED_STRING_ARGUMENT.invoke(getLeftJustified(), "leftJustified");
}
if (!func && hasSignificantDigits()) {
getSignificantDigits().markAsStructuralParameter(checkType);
if (!getSignificantDigits().variability().parameterOrLess())
UNSUPPORTED_NON_FIXED_STRING_ARGUMENT.invoke(getSignificantDigits(), "significantDigits");
}
}
public static final SimpleProblemProducer ASTNode.ONLY_FMU_INTEGER_VARIABLES =
new ComplianceFMUOnlyProducer("ONLY_FMU_INTEGER_VARIABLES", "Integer variables of discrete variability is");
public static final SimpleProblemProducer ASTNode.ONLY_FMU_BOOLEAN_VARIABLES =
new ComplianceFMUOnlyProducer("ONLY_FMU_BOOLEAN_VARIABLES", "Boolean variables of discrete variability is");
public void InstPrimitive.complianceCheck(ErrorCheckType checkType) {
super.complianceCheck(checkType);
if (!myOptions().getBooleanOption("generate_ode")) {
if (isInteger() && !variability().parameterOrLess() && !inFunction())
ONLY_FMU_INTEGER_VARIABLES.invoke(this);
if (isBoolean() && !variability().parameterOrLess())
ONLY_FMU_BOOLEAN_VARIABLES.invoke(this);
}
}
public static final SimpleProblemProducer ASTNode.ONLY_FMU_ENUMERATION_VARIABLES =
new ComplianceFMUOnlyProducer("ONLY_FMU_ENUMERATION_VARIABLES", "Enumeration variables of discrete variability is");
public void InstEnum.complianceCheck(ErrorCheckType checkType) {
super.complianceCheck(checkType);
if (!variability().parameterOrLess())
ONLY_FMU_ENUMERATION_VARIABLES.invoke(this);
}
public static final SimpleProblemProducer ASTNode.ONLY_FMU_FUNCTIONAL_INPUT =
new ComplianceFMUOnlyProducer("ONLY_FMU_FUNCTIONAL_INPUT", "Using functional input arguments is");
public static final SimpleProblemProducer ASTNode.UNSUPPORTED_FUNCTIONAL_INPUT_FROM_FUNCTION_DEFAULT =
new SimpleErrorProducer("UNSUPPORTED_FUNCTIONAL_INPUT_FROM_FUNCTION_DEFAULT", ProblemKind.COMPLIANCE, "Creating functional input arguments from functions with default input arguments is currently not supported");
public static final SimpleProblemProducer ASTNode.UNSUPPORTED_FUNCTIONAL_INPUT_COMPOSITE =
new SimpleErrorProducer("UNSUPPORTED_FUNCTIONAL_INPUT_COMPOSITE", ProblemKind.COMPLIANCE, "Functional input arguments with record/array inputs/outputs is currently not supported");
public static final SimpleProblemProducer ASTNode.UNSUPPORTED_FUNCTIONAL_INPUT_DEFAULT =
new SimpleErrorProducer("UNSUPPORTED_FUNCTIONAL_INPUT_DEFAULT", ProblemKind.COMPLIANCE, "Default values of functional input arguments is currently not supported");
public static final SimpleProblemProducer ASTNode.UNSUPPORTED_FUNCTIONAL_ARRAY_INPUT =
new SimpleErrorProducer("UNSUPPORTED_FUNCTIONAL_ARRAY_INPUT", ProblemKind.COMPLIANCE, "Arrays of functional input arguments is currently not supported");
public void InstPartialFunction.complianceCheck(ErrorCheckType checkType) {
ONLY_FMU_FUNCTIONAL_INPUT.invoke(this);
for (InstComponentDecl icd : myInputs()) {
if (icd.hasBindingExp()) {
UNSUPPORTED_FUNCTIONAL_INPUT_FROM_FUNCTION_DEFAULT.invoke(this);
break;
}
}
for (InstComponentDecl icd : myInputs()) {
if (icd.isComposite()) {
UNSUPPORTED_FUNCTIONAL_INPUT_COMPOSITE.invoke(this);
break;
}
}
for (InstComponentDecl icd : myOutputs()) {
if (icd.isComposite()) {
UNSUPPORTED_FUNCTIONAL_INPUT_COMPOSITE.invoke(this);
break;
}
}
if (hasBindingExp()) {
UNSUPPORTED_FUNCTIONAL_INPUT_DEFAULT.invoke(this);
}
if (isArray())
UNSUPPORTED_FUNCTIONAL_ARRAY_INPUT.invoke(this);
}
public static final SimpleProblemProducer ASTNode.UNSUPPORTED_EXTERNAL_OBJECT_CONSTRUCTORS =
new SimpleErrorProducer("UNSUPPORTED_EXTERNAL_OBJECT_CONSTRUCTORS", ProblemKind.COMPLIANCE, "Constructors for external objects is not supported in functions");
public void InstFunctionCall.complianceCheck(ErrorCheckType checkType) {
if (isConstructorCall() && isBound() && inFunction()) {
UNSUPPORTED_EXTERNAL_OBJECT_CONSTRUCTORS.invoke(this);
}
}
public static final SimpleProblemProducer ASTNode.UNSUPPORTED_EXTERNAL_FUNCTION_RECORD_RETURN_VALUE =
new SimpleErrorProducer("UNSUPPORTED_EXTERNAL_FUNCTION_RECORD_RETURN_VALUE", ProblemKind.COMPLIANCE, "Using records as return value from external functions is not supported");
public void FExternalStmt.complianceCheck(ErrorCheckType checkType) {
getFExternalLanguage().complianceCheck(checkType, this);
}
public void FExternalLanguage.complianceCheck(ErrorCheckType checkType, FExternalStmt stmt) {}
public void FCExternalLanguage.complianceCheck(ErrorCheckType checkType, FExternalStmt stmt) {
if (stmt.hasReturnVar() && stmt.getReturnVar().type().isRecord()) {
UNSUPPORTED_EXTERNAL_FUNCTION_RECORD_RETURN_VALUE.invoke(stmt);
}
}
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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