summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2018-05-29 13:59:13 +0200
committernsensfel <SpamShield0@noot-noot.org>2018-05-29 13:59:13 +0200
commit115448b0b5b5f3df329c34890462d06c4f56e018 (patch)
tree6ea5e3d82ad7961d1cdba9365f96613ef1963568
parentae65703e96e8c51880b9995ef5de27890722b275 (diff)
downloadhastabel2idp-115448b0b5b5f3df329c34890462d06c4f56e018.zip
hastabel2idp-115448b0b5b5f3df329c34890462d06c4f56e018.tar.bz2
Trying (and failing) to use the async FF prop.
-rw-r--r--src/hastabel2idp/Main.java2
-rw-r--r--src/hastabel2idp/idp/Project.java56
-rw-r--r--src/hastabel2idp/idp/Structure.java76
-rw-r--r--src/hastabel2idp/idp/Vocabulary.java47
-rw-r--r--src/hastabel2idp/idp/lang/FunctionCall.java7
-rw-r--r--src/hastabel2idp/idp/lang/OperatorFormula.java1
6 files changed, 174 insertions, 15 deletions
diff --git a/src/hastabel2idp/Main.java b/src/hastabel2idp/Main.java
index c6105ce..f775873 100644
--- a/src/hastabel2idp/Main.java
+++ b/src/hastabel2idp/Main.java
@@ -180,6 +180,8 @@ public class Main
project = new Project(params);
+ System.out.println("# converting:\n" + property.toString());
+
project.generate(params.get_property_name(), world, property);
}
diff --git a/src/hastabel2idp/idp/Project.java b/src/hastabel2idp/idp/Project.java
index 0393e3a..f0aeab7 100644
--- a/src/hastabel2idp/idp/Project.java
+++ b/src/hastabel2idp/idp/Project.java
@@ -4,6 +4,8 @@ import hastabel2idp.Parameters;
import hastabel.World;
+import hastabel2idp.idp.lang.Expression;
+
import hastabel.lang.Formula;
import hastabel.lang.Predicate;
import hastabel.lang.Type;
@@ -64,20 +66,28 @@ public class Project
relevant_signatures = predicate.get_relevant_signatures();
partial_signatures = predicate.get_partial_signatures();
- vocabulary.add_predicate
- (
- predicate,
- relevant_signatures,
- partial_signatures
- );
-
- structure.add_predicate
- (
- predicate,
- relevant_signatures,
- partial_signatures
- );
-
+ if (predicate.is_used_as_predicate())
+ {
+ vocabulary.add_predicate
+ (
+ predicate,
+ relevant_signatures,
+ partial_signatures
+ );
+
+ structure.add_predicate
+ (
+ predicate,
+ relevant_signatures,
+ partial_signatures
+ );
+ }
+
+ if (predicate.is_used_as_function())
+ {
+ vocabulary.add_function(predicate, relevant_signatures);
+ structure.add_function(predicate, relevant_signatures);
+ }
}
}
@@ -123,4 +133,22 @@ public class Project
return sb.toString();
}
+
+ public static String parameters_to_suffix (final List<Expression> params)
+ {
+ final StringBuilder sb;
+
+ sb = new StringBuilder();
+
+ for (final Expression param: params)
+ {
+ if (param != null)
+ {
+ sb.append("_");
+ sb.append(param.get_type().get_name());
+ }
+ }
+
+ return sb.toString();
+ }
}
diff --git a/src/hastabel2idp/idp/Structure.java b/src/hastabel2idp/idp/Structure.java
index 56a8360..c7fb09e 100644
--- a/src/hastabel2idp/idp/Structure.java
+++ b/src/hastabel2idp/idp/Structure.java
@@ -145,4 +145,80 @@ public class Structure
add_predicate_signature(predicate, signature, true);
}
}
+
+ private void add_function_signature
+ (
+ final Predicate predicate,
+ final List<Type> signature
+ )
+ {
+ boolean is_first_member;
+ final Collection<List<Element>> relevant_members;
+
+ out.write(" ");
+ out.write(predicate.get_name());
+ out.write(Project.signature_to_suffix(signature));
+ out.write("_f={");
+ out.insert_newline();
+
+ is_first_member = true;
+
+ relevant_members = predicate.get_relevant_members(signature);
+
+ for (final List<Element> member: relevant_members)
+ {
+ final int signature_size, signature_size_m1;
+ boolean is_first_member_param;
+
+ signature_size = member.size();
+ signature_size_m1 = (signature_size - 1);
+
+ is_first_member_param = true;
+
+ if (is_first_member)
+ {
+ is_first_member = false;
+ out.write(" ");
+ }
+ else
+ {
+ out.write(";");
+ out.insert_newline();
+ out.write(" ");
+ }
+
+ for (int i = 0; i < signature_size_m1; ++i)
+ {
+ if (is_first_member_param)
+ {
+ is_first_member_param = false;
+ }
+ else
+ {
+ out.write(", ");
+ }
+
+ out.write(member.get(i).get_name());
+ }
+
+ out.write("->");
+ out.write(member.get(signature_size_m1).get_name());
+ }
+
+ out.insert_newline();
+ out.write(" }");
+ out.insert_newline();
+ }
+
+ public void add_function
+ (
+ final Predicate predicate,
+ final Collection<List<Type>> relevant_signatures
+ )
+ {
+ for (final List<Type> signature: relevant_signatures)
+ {
+ add_function_signature(predicate, signature);
+ }
+ }
}
diff --git a/src/hastabel2idp/idp/Vocabulary.java b/src/hastabel2idp/idp/Vocabulary.java
index 0794ffd..ca9f591 100644
--- a/src/hastabel2idp/idp/Vocabulary.java
+++ b/src/hastabel2idp/idp/Vocabulary.java
@@ -76,6 +76,41 @@ public class Vocabulary
out.insert_newline();
}
+ private void add_function_signature
+ (
+ final Predicate predicate,
+ final List<Type> signature
+ )
+ {
+ final int signature_size, signature_size_m1;
+ boolean is_first;
+
+ signature_size = signature.size();
+ signature_size_m1 = (signature_size - 1);
+
+ is_first = true;
+
+ out.write(" ");
+ out.write(predicate.get_name());
+ out.write(Project.signature_to_suffix(signature));
+ out.write("_f(");
+
+ if (0 < signature_size_m1)
+ {
+ out.write(signature.get(0).get_name());
+ }
+
+ for (int i = 1; i < signature_size_m1; ++i)
+ {
+ out.write(", ");
+ out.write(signature.get(i).get_name());
+ }
+
+ out.write("):");
+ out.write(signature.get(signature_size_m1).get_name());
+ out.insert_newline();
+ }
+
public void add_predicate
(
final Predicate predicate,
@@ -94,6 +129,18 @@ public class Vocabulary
}
}
+ public void add_function
+ (
+ final Predicate predicate,
+ final Collection<List<Type>> relevant_signatures
+ )
+ {
+ for (final List<Type> signature: relevant_signatures)
+ {
+ add_function_signature(predicate, signature);
+ }
+ }
+
public void add_target_predicate
(
final String name,
diff --git a/src/hastabel2idp/idp/lang/FunctionCall.java b/src/hastabel2idp/idp/lang/FunctionCall.java
index ee0137e..cd81c7b 100644
--- a/src/hastabel2idp/idp/lang/FunctionCall.java
+++ b/src/hastabel2idp/idp/lang/FunctionCall.java
@@ -1,5 +1,7 @@
package hastabel2idp.idp.lang;
+import hastabel2idp.idp.Project;
+
import hastabel.lang.Predicate;
import java.util.List;
@@ -55,7 +57,10 @@ class FunctionCall extends Expression
sb = new StringBuilder();
sb.append(parent.get_name());
- // TODO: add signature suffix
+ Project.parameters_to_suffix(params);
+ sb.append("_f(");
+
+ is_first = true;
for (final Expression param: params)
{
diff --git a/src/hastabel2idp/idp/lang/OperatorFormula.java b/src/hastabel2idp/idp/lang/OperatorFormula.java
index 818ea6d..67fb604 100644
--- a/src/hastabel2idp/idp/lang/OperatorFormula.java
+++ b/src/hastabel2idp/idp/lang/OperatorFormula.java
@@ -13,6 +13,7 @@ class OperatorFormula extends Formula
final List<Formula> params
)
{
+
this.parent = parent;
this.params = params;
}