Skip to content

Commit

Permalink
- Some fixes to dumping as corba string
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@11675 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Apr 5, 2012
1 parent fedb0ed commit 554a5b3
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 34 deletions.
55 changes: 34 additions & 21 deletions Compiler/FrontEnd/Dump.mo
Expand Up @@ -5707,6 +5707,7 @@ algorithm
local
Absyn.Path path;
Integer i;
Absyn.FunctionRestriction functionRestriction;

case Absyn.R_CLASS()
equation
Expand Down Expand Up @@ -5753,26 +5754,13 @@ algorithm
Print.printBuf("record Absyn.R_PACKAGE end Absyn.R_PACKAGE;");
then ();

case Absyn.R_FUNCTION(Absyn.FR_NORMAL_FUNCTION())
case Absyn.R_FUNCTION(functionRestriction=functionRestriction)
equation
Print.printBuf("record Absyn.FR_NORMAL_FUNCTION end Absyn.FR_NORMAL_FUNCTION;");
Print.printBuf("record Absyn.R_FUNCTION functionRestriction = ");
printFunctionRestrictionAsCorbaString(functionRestriction);
Print.printBuf("end Absyn.R_FUNCTION;");
then ();

case Absyn.R_FUNCTION(Absyn.FR_OPERATOR_FUNCTION())
equation
Print.printBuf("record Absyn.FR_OPERATOR_FUNCTION end Absyn.FR_OPERATOR_FUNCTION;");
then ();

case Absyn.R_FUNCTION(Absyn.FR_PARALLEL_FUNCTION())
equation
Print.printBuf("record Absyn.FR_PARALLEL_FUNCTION end Absyn.FR_PARALLEL_FUNCTION;");
then ();

case Absyn.R_FUNCTION(Absyn.FR_KERNEL_FUNCTION())
equation
Print.printBuf("record Absyn.FR_KERNEL_FUNCTION end Absyn.FR_KERNEL_FUNCTION;");
then ();

case Absyn.R_OPERATOR()
equation
Print.printBuf("record Absyn.R_OPERATOR end Absyn.R_OPERATOR;");
Expand Down Expand Up @@ -5831,6 +5819,29 @@ algorithm
end match;
end printRestrictionAsCorbaString;

protected function printFunctionRestrictionAsCorbaString
input Absyn.FunctionRestriction functionRestriction;
algorithm
_ := match functionRestriction
case Absyn.FR_NORMAL_FUNCTION()
equation
Print.printBuf("record Absyn.FR_NORMAL_FUNCTION end Absyn.FR_NORMAL_FUNCTION;");
then ();
case Absyn.FR_OPERATOR_FUNCTION()
equation
Print.printBuf("record Absyn.FR_OPERATOR_FUNCTION end Absyn.FR_OPERATOR_FUNCTION;");
then ();
case Absyn.FR_PARALLEL_FUNCTION()
equation
Print.printBuf("record Absyn.FR_PARALLEL_FUNCTION end Absyn.FR_PARALLEL_FUNCTION;");
then ();
case Absyn.FR_KERNEL_FUNCTION()
equation
Print.printBuf("record Absyn.FR_KERNEL_FUNCTION end Absyn.FR_KERNEL_FUNCTION;");
then ();
end match;
end printFunctionRestrictionAsCorbaString;

protected function printClassPartAsCorbaString
input Absyn.ClassPart classPart;
algorithm
Expand Down Expand Up @@ -6215,7 +6226,7 @@ algorithm
Print.printBuf(", comment = ");
printOption(comment, printCommentAsCorbaString);
Print.printBuf(", info = ");
printInfo(info);
printInfoAsCorbaString(info);
Print.printBuf(" end Absyn.EQUATIONITEM;");
then ();
case Absyn.EQUATIONITEMANN(annotation_)
Expand Down Expand Up @@ -6681,7 +6692,7 @@ algorithm
Absyn.ElementSpec elementSpec;
Option<Absyn.ConstrainClass> constrainClass;
Absyn.Info info;
case Absyn.MODIFICATION(finalPrefix,eachPrefix,componentRef,modification,comment,_)
case Absyn.MODIFICATION(finalPrefix,eachPrefix,componentRef,modification,comment,info)
equation
Print.printBuf("record Absyn.MODIFICATION finalPrefix = ");
Print.printBuf(Util.if_(finalPrefix,"true","false"));
Expand All @@ -6693,6 +6704,8 @@ algorithm
printOption(modification, printModificationAsCorbaString);
Print.printBuf(", comment = ");
printStringCommentOption(comment);
Print.printBuf(", info = ");
printInfoAsCorbaString(info);
Print.printBuf(" end Absyn.MODIFICATION;");
then ();
case Absyn.REDECLARATION(finalPrefix,redeclareKeywords,eachPrefix,elementSpec,constrainClass,info)
Expand Down Expand Up @@ -6753,11 +6766,11 @@ algorithm
equation
Print.printBuf("record Absyn.ITERATOR name = \"");
Print.printBuf(id);
Print.printBuf("\", guard = ");
Print.printBuf("\", guardExp = ");
printOption(guardExp,printExpAsCorbaString);
Print.printBuf(", range = ");
printOption(range,printExpAsCorbaString);
Print.printBuf(")");
Print.printBuf("end Absyn.ITERATOR;");
then ();
end match;
end printForIteratorAsCorbaString;
Expand Down
Expand Up @@ -94,9 +94,9 @@ public ModelicaRecord(String recordName,
Class<? extends ModelicaObject>[] fieldTypes,
ModelicaObject... values) throws ModelicaRecordException {
if (fieldNames.length != fieldTypes.length)
throw new ModelicaRecordException("Length of field names and types differ");
throw new ModelicaRecordException("Length of field names ("+fieldNames.length+") and types ("+fieldTypes.length+") differ";
if (fieldNames.length != values.length)
throw new ModelicaRecordException("Length of field names and source record differ");
throw new ModelicaRecordException("Length of field names ("+fieldNames.length+") and source ("+values.length+") record differ";

this.recordName = recordName;
spec = allRecords.get(recordName);
Expand All @@ -123,9 +123,9 @@ public ModelicaRecord(String recordName,
Class<? extends ModelicaObject>[] fieldTypes,
Map<String,ModelicaObject> map) throws ModelicaRecordException {
if (fieldNames.length != fieldTypes.length)
throw new ModelicaRecordException("Length of field names and types differ");
throw new ModelicaRecordException("Length of field names ("+fieldNames.length+")and types ("+fieldTypes.length+")differ");
if (fieldNames.length != map.size())
throw new ModelicaRecordException("Length of field names and source record differ");
throw new ModelicaRecordException("Length of field names ("+fieldNames.length+")and source record ("+map.size()+") differ");

this.recordName = recordName;
spec = allRecords.get(recordName);
Expand Down
Expand Up @@ -8,13 +8,15 @@
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.io.LineNumberReader;

import org.openmodelica.ModelicaAny;
import org.openmodelica.ModelicaObject;
import org.openmodelica.SimpleTypeSpec;
import org.openmodelica.TypeSpec;

public class OMCStringParser {
private static int sizeError = 300;
public static ModelicaObject parse(String s) throws ParseException {
return parse(s,SimpleTypeSpec.modelicaObject);
}
Expand All @@ -23,20 +25,20 @@ public static <T extends ModelicaObject> T parse(String s, Class<T> c) throws Pa
return parse(s,new SimpleTypeSpec<T>(c));
}
public static <T extends ModelicaObject> T parse(String s, TypeSpec<T> spec) throws ParseException {
Reader input = new StringReader(s);
LineNumberReader input = new LineNumberReader(new StringReader(s));
try {
return parse(input,spec);
} catch (ParseException ex) {
char[] cbuf = new char[40];
char[] cbuf = new char[sizeError];
String str;
try {
input.read(cbuf,0,40);
input.read(cbuf,0,sizeError);
str = new String(cbuf);
File f = File.createTempFile("OMCStringParser", ".log");
FileWriter fw = new FileWriter(f);
fw.write(s);
fw.close();
throw new ParseException("Original string saved to file "+f+"\nNext characters in stream: " + str,ex);
throw new ParseException("Original string saved to file "+f+"\nFailed at line: "+input.getLineNumber()+", next characters in stream: " + str,ex);
} catch (IOException ex2) {
throw new ParseException(ex);
}
Expand Down Expand Up @@ -66,17 +68,17 @@ public static <T extends ModelicaObject> T parse(File f, Class<T> c) throws Pars
return parse(f,new SimpleTypeSpec<T>(c));
}
public static <T extends ModelicaObject> T parse(File f, TypeSpec<T> spec) throws ParseException, FileNotFoundException {
Reader input;
input = new BufferedReader(new FileReader(f));
LineNumberReader input;
input = new LineNumberReader(new BufferedReader(new FileReader(f)));
try {
return parse(input,spec);
} catch (ParseException ex) {
char[] cbuf = new char[40];
char[] cbuf = new char[sizeError];
String str;
try {
input.read(cbuf,0,40);
input.read(cbuf,0,sizeError);
str = new String(cbuf);
throw new ParseException("Original file: "+f+"\nNext characters in stream: " + str,ex);
throw new ParseException("Original file: "+f+"\nFailed at line: "+input.getLineNumber()+", next characters in stream: " + str,ex);
} catch (IOException ex2) {
throw new ParseException(ex);
}
Expand Down

0 comments on commit 554a5b3

Please sign in to comment.