Skip to content

Commit

Permalink
Update ProtoTuple.
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertHSchmidt committed Feb 1, 2018
1 parent bb5cb2a commit 086f06b
Show file tree
Hide file tree
Showing 12 changed files with 270 additions and 7 deletions.
14 changes: 14 additions & 0 deletions src/java/boa/types/proto/ASTRootProtoTuple.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
import java.util.List;
import java.util.Map;

import boa.types.BoaInt;
import boa.types.BoaProtoList;
import boa.types.BoaProtoTuple;
import boa.types.BoaString;
import boa.types.BoaType;
import boa.types.proto.enums.ChangeKindProtoMap;

/**
* A {@link ASTRootProtoTuple}.
Expand All @@ -40,6 +42,18 @@ public class ASTRootProtoTuple extends BoaProtoTuple {

names.put("namespaces", counter++);
members.add(new BoaProtoList(new NamespaceProtoTuple()));

names.put("names", counter++);
members.add(new BoaString());

names.put("change_kind", counter++);
members.add(new ChangeKindProtoMap());

names.put("mapped_node", counter++);
members.add(new BoaInt());

names.put("key", counter++);
members.add(new BoaInt());
}

/**
Expand Down
15 changes: 14 additions & 1 deletion src/java/boa/types/proto/ChangedFileProtoTuple.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.List;
import java.util.Map;

import boa.types.BoaBool;
import boa.types.BoaInt;
import boa.types.BoaProtoList;
import boa.types.BoaProtoTuple;
Expand Down Expand Up @@ -53,15 +54,27 @@ public class ChangedFileProtoTuple extends BoaProtoTuple {
// NOTE: this is here to make reachableTypes() work properly
names.put("_placeholder_", counter++);
members.add(new ASTRootProtoTuple());

names.put("key", counter++);
members.add(new BoaInt());

names.put("ast", counter++);
members.add(new BoaBool());

names.put("comments", counter++);
members.add(new CommentsRootProtoTuple());

names.put("changes", counter++);
members.add(new BoaProtoList(new ChangeKindProtoMap()));

names.put("previous_versions", counter++);
members.add(new BoaProtoList(new BoaInt()));

names.put("previous_index", counter++);
names.put("previous_indices", counter++);
members.add(new BoaProtoList(new BoaInt()));

names.put("mapped_key", counter++);
members.add(new BoaInt());
}

/**
Expand Down
12 changes: 11 additions & 1 deletion src/java/boa/types/proto/CommentProtoTuple.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import boa.types.BoaProtoTuple;
import boa.types.BoaString;
import boa.types.BoaType;
import boa.types.proto.enums.ChangeKindProtoMap;
import boa.types.proto.enums.CommentKindProtoMap;

/**
Expand All @@ -45,7 +46,16 @@ public class CommentProtoTuple extends BoaProtoTuple {
names.put("value", count++);
members.add(new BoaString());

names.put("start_line", count++);
names.put("position", count++);
members.add(new PositionInfoProtoTuple());

names.put("change_kind", count++);
members.add(new ChangeKindProtoMap());

names.put("mapped_node", count++);
members.add(new BoaInt());

names.put("key", count++);
members.add(new BoaInt());
}

Expand Down
20 changes: 20 additions & 0 deletions src/java/boa/types/proto/DeclarationProtoTuple.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
import java.util.List;
import java.util.Map;

import boa.types.BoaInt;
import boa.types.BoaProtoList;
import boa.types.BoaProtoTuple;
import boa.types.BoaString;
import boa.types.BoaType;
import boa.types.proto.enums.ChangeKindProtoMap;
import boa.types.proto.enums.TypeKindProtoMap;

/**
Expand Down Expand Up @@ -65,6 +67,24 @@ public class DeclarationProtoTuple extends BoaProtoTuple {

names.put("comments", counter++);
members.add(new BoaProtoList(new CommentProtoTuple()));

names.put("change_kind", counter++);
members.add(new ChangeKindProtoMap());

names.put("mapped_node", counter++);
members.add(new BoaInt());

names.put("key", counter++);
members.add(new BoaInt());

names.put("fully_qualified_name", counter++);
members.add(new BoaString());

names.put("declaring_type", counter++);
members.add(new BoaInt());

names.put("statements", counter++);
members.add(new BoaProtoList(new StatementProtoTuple()));
}

/**
Expand Down
45 changes: 45 additions & 0 deletions src/java/boa/types/proto/ExpressionProtoTuple.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
import java.util.Map;

import boa.types.BoaBool;
import boa.types.BoaInt;
import boa.types.BoaProtoList;
import boa.types.BoaProtoTuple;
import boa.types.BoaString;
import boa.types.BoaType;
import boa.types.proto.enums.ChangeKindProtoMap;
import boa.types.proto.enums.ExpressionKindProtoMap;

/**
Expand Down Expand Up @@ -75,6 +77,49 @@ public class ExpressionProtoTuple extends BoaProtoTuple {

names.put("annotation", counter++);
members.add(new ModifierProtoTuple());

names.put("no_parens", counter++);
members.add(new BoaBool());

names.put("change_kind", counter++);
members.add(new ChangeKindProtoMap());

names.put("mapped_node", counter++);
members.add(new BoaInt());

names.put("key", counter++);
members.add(new BoaInt());

names.put("declaring_type", counter++);
members.add(new TypeProtoTuple());

names.put("return_type", counter++);
members.add(new TypeProtoTuple());

names.put("methods", counter++);
members.add(new BoaProtoList(new MethodProtoTuple()));

names.put("statements", counter++);
members.add(new BoaProtoList(new StatementProtoTuple()));

names.put("is_member_access", counter++);
members.add(new BoaBool());

names.put("dolar_sign", counter++);
members.add(new BoaBool());

names.put("computed_method", counter++);
members.add(new ExpressionProtoTuple());

names.put("is_static", counter++);
members.add(new BoaBool());

names.put("has_from", counter++);
members.add(new BoaBool());

names.put("trait", counter++);
members.add(new MethodProtoTuple());

}

/**
Expand Down
17 changes: 17 additions & 0 deletions src/java/boa/types/proto/MethodProtoTuple.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
import java.util.List;
import java.util.Map;

import boa.types.BoaInt;
import boa.types.BoaProtoList;
import boa.types.BoaProtoTuple;
import boa.types.BoaString;
import boa.types.BoaType;
import boa.types.proto.enums.ChangeKindProtoMap;

/**
* A {@link MethodProtoTuple}.
Expand Down Expand Up @@ -61,6 +63,21 @@ public class MethodProtoTuple extends BoaProtoTuple {

names.put("comments", counter++);
members.add(new BoaProtoList(new CommentProtoTuple()));

names.put("change_kind", counter++);
members.add(new ChangeKindProtoMap());

names.put("mapped_node", counter++);
members.add(new BoaInt());

names.put("key", counter++);
members.add(new BoaInt());

names.put("declaring_type", counter++);
members.add(new BoaInt());

names.put("computed_name", counter++);
members.add(new ExpressionProtoTuple());
}

/**
Expand Down
15 changes: 15 additions & 0 deletions src/java/boa/types/proto/ModifierProtoTuple.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@
import java.util.List;
import java.util.Map;

import boa.types.BoaInt;
import boa.types.BoaProtoList;
import boa.types.BoaProtoTuple;
import boa.types.BoaString;
import boa.types.BoaType;
import boa.types.proto.enums.ChangeKindProtoMap;
import boa.types.proto.enums.ModifierKindProtoMap;
import boa.types.proto.enums.ScopeProtoMap;
import boa.types.proto.enums.VisibilityProtoMap;

/**
Expand Down Expand Up @@ -57,6 +60,18 @@ public class ModifierProtoTuple extends BoaProtoTuple {

names.put("other", counter++);
members.add(new BoaString());

names.put("change_kind", counter++);
members.add(new ChangeKindProtoMap());

names.put("mapped_node", counter++);
members.add(new BoaInt());

names.put("key", counter++);
members.add(new BoaInt());

names.put("scope", counter++);
members.add(new ScopeProtoMap());
}

/**
Expand Down
17 changes: 14 additions & 3 deletions src/java/boa/types/proto/NamespaceProtoTuple.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
import java.util.List;
import java.util.Map;

import boa.types.BoaInt;
import boa.types.BoaProtoList;
import boa.types.BoaProtoTuple;
import boa.types.BoaString;
import boa.types.BoaType;
import boa.types.proto.enums.ChangeKindProtoMap;

/**
* A {@link NamespaceProtoTuple}.
Expand All @@ -46,9 +48,6 @@ public class NamespaceProtoTuple extends BoaProtoTuple {

names.put("declarations", counter++);
members.add(new BoaProtoList(new DeclarationProtoTuple()));

names.put("comments", counter++);
members.add(new BoaProtoList(new CommentProtoTuple()));

names.put("statements", counter++);
members.add(new BoaProtoList(new StatementProtoTuple()));
Expand All @@ -59,11 +58,23 @@ public class NamespaceProtoTuple extends BoaProtoTuple {
names.put("expressions", counter++);
members.add(new BoaProtoList(new ExpressionProtoTuple()));

names.put("change_kind", counter++);
members.add(new ChangeKindProtoMap());

names.put("mapped_node", counter++);
members.add(new BoaInt());

names.put("key", counter++);
members.add(new BoaInt());

names.put("namespaces", counter++);
members.add(new BoaProtoList(new NamespaceProtoTuple()));

names.put("imports", counter++);
members.add(new BoaProtoList(new BoaString()));

names.put("variables", counter++);
members.add(new BoaProtoList(new VariableProtoTuple()));
}

/**
Expand Down
53 changes: 53 additions & 0 deletions src/java/boa/types/proto/PositionInfoProtoTuple.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package boa.types.proto;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import boa.types.BoaInt;
import boa.types.BoaProtoTuple;
import boa.types.BoaString;
import boa.types.BoaType;
import boa.types.proto.enums.CommentKindProtoMap;

public class PositionInfoProtoTuple extends BoaProtoTuple {
private final static List<BoaType> members = new ArrayList<BoaType>();
private final static Map<String, Integer> names = new HashMap<String, Integer>();

static {
int count = 0;

names.put("start_pos", count++);
members.add(new BoaInt());

names.put("length", count++);
members.add(new BoaInt());

names.put("start_line", count++);
members.add(new BoaInt());

names.put("start_col", count++);
members.add(new BoaInt());

names.put("end_line", count++);
members.add(new BoaInt());

names.put("end_col", count++);
members.add(new BoaInt());
}

/**
* Construct a {@link PositionInfoProtoTuple}.
*/
public PositionInfoProtoTuple() {
super(members, names);
}

/** @{inheritDoc} */
@Override
public String toJavaType() {
return "boa.types.Ast.PositionInfo";
}

}
Loading

5 comments on commit 086f06b

@nguyenhoan
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@psybers
@RobertHSchmidt and I were updating the proto tuples and ran into a StackOverflowException when calculating hash code.
https://travis-ci.org/boalang/compiler/builds/336227992?utm_source=github_status&utm_medium=notification

After debugging, I found that the exception caused by adding recursive types at
086f06b#diff-54bc380eac6850531ef850933f83ab26R112
086f06b#diff-54bc380eac6850531ef850933f83ab26R121
086f06b#diff-83a2c3c5479302f4aa396a5e9c0eaa5aR71

I don't think recursive types are not allowed in Boa because we have been doing that.

For example, Expression type contains expressions and arguments of type Expression.

Talking about that recursive type of Expression, I saw that there was no exception because expressions and arguments are BoaProtoList whose hashCode() method was not overridden. I believe not having hashCode() method overridden is a bug.

What do you think?

@psybers
Copy link
Member

@psybers psybers commented on 086f06b Feb 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very odd. If you run 'ant test-codegen' you get that stack overflow. But if you run the compiler one at a time on all the test cases, it runs without problem...

@nguyenhoan
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran the JUnit test on boa.test.compiler.TestGood and got the same stack overflow.

@psybers
Copy link
Member

@psybers psybers commented on 086f06b Feb 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So somehow running from JUnit is differing from running with compile.sh.

Does it fail for each unit test or just one specific?

@nguyenhoan
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It failed for each unit test in both compiler and datagen.

Please sign in to comment.