diff --git a/.gitignore b/.gitignore
index c6aa4d053..e24fe0bbb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,11 +9,19 @@ tools/eclipse/plugins/org.scribble.*/bin/
*~
*.swp
*.bak
+*.versionsBackup
+
+.idea
+**/*.iml
javadoc
+
+##
#scribble-demos/scrib
+scribble-demos/scrib/Makefile
+scribble-demos/scrib/tutorial/src/tutorial/adder/Adder/
scribble-demos/scrib/betty16/src/betty16/lec1/httplong/HttpLong/
scribble-demos/scrib/betty16/src/betty16/lec1/httpshort/HttpShort/
scribble-demos/scrib/betty16/src/betty16/lec2/adder/Adder/
@@ -33,26 +41,36 @@ scribble-demos/scrib/smtp/src/smtp/Smtp/
scribble-demos/scrib/travel/src/travel/Travel/
scribble-demos/scrib/tutorial/src/tutorial/adder/Adder/
-#scribble-core/src/test/scrib
-
-scribble-core/src/test/scrib/exercise/calculator/EProtocol/
-scribble-core/src/test/scrib/exercise/voting/EProtocol/
-
-scribble-core/src/test/scrib/demo/fase17/travel/TravelAgent/
-scribble-core/src/test/scrib/demo/fase17/travel2/TravelAgent2/
-
-scribble-core/src/test/scrib/scratch/scratch1/
-scribble-core/src/test/scrib/scratch/scratch2/
-scribble-core/src/test/scrib/test/foo/Foo/
-scribble-core/src/test/scrib/test/test1/
-scribble-core/src/test/scrib/test/test2/
-scribble-core/src/test/scrib/test/test3/
-scribble-core/src/test/scrib/test/test4/
-scribble-core/src/test/scrib/test/test5/
-scribble-core/src/test/scrib/test/test6/
-scribble-core/src/test/scrib/test/test7/
-scribble-core/src/test/scrib/test/test8/
-scribble-core/src/test/scrib/test/test9/
+
+##
+#scribble-test/src/test/scrib
+
+scribble-test/src/test/scrib/exercise/calculator/EProtocol/
+scribble-test/src/test/scrib/exercise/voting/EProtocol/
+
+scribble-test/src/test/scrib/demo/fase17/travel/TravelAgent/
+scribble-test/src/test/scrib/demo/fase17/travel2/TravelAgent2/
+scribble-test/src/test/scrib/demo/highlow/HighLow/
+
+scribble-test/src/test/scrib/scratch/scratch1/
+scribble-test/src/test/scrib/scratch/scratch2/
+scribble-test/src/test/scrib/test/foo/Foo/
+scribble-test/src/test/scrib/test/test1/
+scribble-test/src/test/scrib/test/test2/
+scribble-test/src/test/scrib/test/test3/
+scribble-test/src/test/scrib/test/test4/
+scribble-test/src/test/scrib/test/test5/
+scribble-test/src/test/scrib/test/test6/
+scribble-test/src/test/scrib/test/test7/
+scribble-test/src/test/scrib/test/test8/
+scribble-test/src/test/scrib/test/test9/
+
+scribble-test/src/test/scrib/test/test2/Test2/
+scribble-test/src/test/scrib/test/test3/Test3/
+scribble-test/src/test/scrib/test/test4/Test4/
+scribble-test/src/test/scrib/test/test5/Test5/
+scribble-test/src/test/scrib/test/test6/Test6/
+scribble-test/src/test/scrib/test/test7/Test7/
bin/scribblec.sh
diff --git a/README.md b/README.md
index 7ee299c2b..408b44a3a 100644
--- a/README.md
+++ b/README.md
@@ -2,17 +2,19 @@
# Java Tooling for Scribble
-This project provides Java tooling/libraries for the Scribble multi-party protocol definition language.
+This project provides Java tooling/libraries for the Scribble multi-party
+protocol definition language.
## Building from source
-First step is to clone this git repository locally. Once available, run the following maven command to build
-the project:
+First step is to clone this git repository locally. Once available, run the
+following maven command to build the project:
mvn [clean] install
-The distribution will be available from the folder _scribble-dist/target_. The contents of the zip is:
+The distribution will be available from the folder _scribble-dist/target_. The
+contents of the zip is:
- lib jars needed to run the scribble-java tool
- scribblec.sh script for running the command line tool
@@ -20,21 +22,20 @@ The distribution will be available from the folder _scribble-dist/target_. The c
## Command line usage:
+Assuming scribblec.sh has been extracted from the above zip:
+
> List command line options.
./scribblec.sh --help
+Assuming a Scribble module file Test.scr in the same directory:
-> Check well-formedness of global protocols in, e.g., Test.scr.
+> Check well-formedness of global protocols in module Test.scr.
./scribblec.sh Test.scr
-Notes:
-- Use the -oldwf command line flag to use the simpler syntactic protocol
- well-formedness from the previous version of Scribble.
-- Use the -V command line flag to obtain full traces for errors according
- to the new protocol validation (and other details).
-
+Note: try the -V command line flag to obtain full traces for errors (and other
+ details).
> Project local protocol for role "C" of protocol "Proto" in Test.scr
@@ -52,6 +53,8 @@ Notes:
./scribblec.sh -d . Test.scr -api Proto C
+Note: omitting the -d argument will print the output to stdout.
+
## Examples:
@@ -64,8 +67,8 @@ Further examples can be found in:
https://github.com/scribble/scribble-java/tree/master/scribble-demos/scrib
-The distribution zip does not include these examples. They can be obtained
-as part of the source repository, or separately via the above link.
+The distribution zip does not include these examples. They can be obtained as
+part of the source repository, or separately via the above link.
> E.g. To generate the Java Endpoint API for role "C" in the "Adder" protocol from the
Scribble-Java tutorial (http://www.scribble.org/docs/scribble-java.html#QUICK)
@@ -93,7 +96,7 @@ Or try (from Nick Ng):
Bugs and issues can be reported via the github Issues facility.
-Or email rhu1234 [at] doc.ic.ac.uk excluding the 1234.
+Or email r.z.h.hu1234 [at] herts.ac.uk excluding the 1234.
[ci-img]: https://travis-ci.org/scribble/scribble-java.svg?branch=master
@@ -102,3 +105,4 @@ Or email rhu1234 [at] doc.ic.ac.uk excluding the 1234.
[cov]: https://coveralls.io/github/scribble/scribble-java?branch=master
[maven-img]: https://img.shields.io/maven-central/v/org.scribble/scribble-core.svg?maxAge=2592000
[maven]: http://search.maven.org/#search%7Cga%7C1%7Cscribble-core
+
diff --git a/pom.xml b/pom.xml
index f0181a08d..188655f30 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,384 +1,418 @@
+
+
+ 4.0.0
-
+ org.scribble
+ parent
+ 0.5.1-SNAPSHOT
+ pom
+
+
+
+ org.scribble
+ scribble-core
+ ${project.version}
+
+
+ org.scribble
+ scribble-parser
+ ${project.version}
+
+
+ org.scribble
+ scribble-ast
+ ${project.version}
+
+
+ org.scribble
+ scribble-cli
+ ${project.version}
+
+
+ org.scribble
+ scribble-runtime
+ ${project.version}
+
+
+ org.scribble
+ scribble-codegen
+ ${project.version}
+
+
+ org.scribble
+ scribble-main
+ ${project.version}
+
+
+
+ org.scribble
+ scribble-test
+ ${project.version}
+
-
- 4.0.0
- org.scribble
- parent
- 0.4.4-SNAPSHOT
- pom
- scribble-java
- http://www.scribble.org
-
- Scribble
-
+
+ org.antlr
+ antlr-runtime
+ ${antlr.version}
+
+
+ junit
+ junit
+ ${junit.version}
+
+
+ commons-io
+ commons-io
+ ${version.commons-io}
+
+
+
+
-
- https://github.com/scribble/scribble-java
- scm:git:https://github.com/scribble/scribble-java.git
- scm:git:https://github.com/scribble/scribble-java.git
- HEAD
-
+
+ scribble-core
+ scribble-runtime
+ scribble-ast
+ scribble-parser
+ scribble-codegen
+ scribble-main
+ scribble-cli
+ scribble-test
+ scribble-dist
+ scribble-demos
+
-
-
- Apache 2
- http://www.apache.org/licenses/LICENSE-2.0.txt
- repo
- Apache License V2
-
-
+
+ 3.4
+ 4.13.1
+
+
+ 2.7
-
-
- Gary Brown
- objectiser
- gary.pi4tech@gmail.com
- Scribble.org
-
- Developer
-
- +0
-
-
+
+ 1.8
+ 1.8
+ true
- 2008
+
+ 2.5.3
+ 3.2.1
+
+ 2.9
+ 0.3.4
+ 0.1.0
+
-
- Scribble
- http://www.scribble.org
-
+ UTF-8
+
-
- 3.4
- 1.2.14
- 1.9.9
- 4.11
- 2.4
+ scribble-java
+ Scribble
+ http://www.scribble.org
+ 2008
-
- 1.8
- 1.8
- true
+
+
+ Apache 2
+ http://www.apache.org/licenses/LICENSE-2.0.txt
+ repo
+ Apache License V2
+
+
- 2.8.2
- 2.5.3
- 3.0.1
- 2.10.4
- 0.3.4
- 0.1.0
-
+
+ Scribble
+ http://www.scribble.org
+
-
- scribble-core
- scribble-parser
- scribble-cli
- scribble-codegen
- scribble-runtime
- scribble-test
- scribble-dist
- scribble-demos
-
+
+
+ Gary Brown
+ objectiser
+ gary.pi4tech@gmail.com
+ Scribble.org
+
+ Developer
+
+ +0
+
+
+ Raymond Hu
+ rhu1
+ r.z.h.hu@herts.ac.uk
+ University of Hertfordshire
+
+ Developer
+
+ +0
+
+
-
-
-
- org.scribble
- scribble-core
- ${project.version}
-
-
- org.scribble
- scribble-parser
- ${project.version}
-
-
- org.scribble
- scribble-cli
- ${project.version}
-
-
- org.scribble
- scribble-runtime
- ${project.version}
-
-
- org.scribble
- scribble-codegen
- ${project.version}
-
-
-
- org.scribble
- scribble-test
- ${project.version}
-
-
- org.antlr
- antlr-runtime
- ${antlr.version}
-
-
- junit
- junit
- ${junit.version}
-
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ 2.2
+
+
+ org.apache.maven.plugins
+ maven-javadoc-plugin
+ ${version.maven-javadoc-plugin}
+
+
+ org.apache.maven.plugins
+ maven-antrun-plugin
+ 1.7
+
+
+ org.apache.maven.plugins
+ maven-assembly-plugin
+ 2.4
+
+
+ org.jboss.maven.plugins
+ maven-jdocbook-plugin
+ 2.3.8
+
+
+ com.mycila
+ license-maven-plugin
+ 3.0
+
-
- commons-io
- commons-io
- ${version.commons-io}
-
-
- org.codehaus.jackson
- jackson-core-asl
- ${jackson.version}
-
-
- org.codehaus.jackson
- jackson-mapper-asl
- ${jackson.version}
-
-
- log4j
- log4j
- ${log4j.version}
-
-
-
+
+
+ io.takari
+ maven
+ ${version.io.takari-maven}
+
+
+
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-jar-plugin
- 2.2
-
-
- org.apache.maven.plugins
- maven-javadoc-plugin
- 2.9
-
-
- org.apache.maven.plugins
- maven-antrun-plugin
- 1.7
-
-
- org.apache.maven.plugins
- maven-assembly-plugin
- 2.4
-
-
- org.jboss.maven.plugins
- maven-jdocbook-plugin
- 2.3.8
-
-
- com.mycila
- license-maven-plugin
- 3.0
-
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.2
+
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+ ${version.maven-source-plugin}
+
+
+ attach-sources
+ verify
+
+ jar
+
+
+
+
+
+ maven-surefire-plugin
+ 2.5
+
+
+ **/*TestCase.java
+ **/*Test.java
+
+
+ **/ScribAllTest.java
+
+
+
-
-
- io.takari
- maven
- ${version.io.takari-maven}
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
- 3.2
-
-
-
- org.apache.maven.plugins
- maven-source-plugin
-
-
- attach-sources
- verify
-
- jar
-
-
-
-
-
- maven-surefire-plugin
- 2.5
-
-
- **/*TestCase.java
- **/*Test.java
-
-
- **/ScribAllTest.java
-
-
-
+
+
+ com.mycila
+ license-maven-plugin
+
+
+ true
+ true
+
+ **/*.xml
+ **/*.g
+ **/*.scr
+ **/*.policy
+ **/*.txt
+ mvnw
+ mvnw.cmd
+ travis/publish.sh
+ .mvn/wrapper/maven-wrapper.properties
+ **/*.versionsBackup
+ **/Scribble-0.3.original
+ bin/*.sh
+ scribblec.sh
+ **/*.swp
+ scribble-test/**/*.*
+
+ **/IGNORE
+
+ scribble-f17/**/*
+
+
+
+
+
+ check
+
+ compile
+
+
+
+
+ maven-release-plugin
+ ${version.maven-release-plugin}
+
+ false
+ release
+ true
+ @{project.version}
+
+
+
+ io.zipkin.centralsync-maven-plugin
+ centralsync-maven-plugin
+ ${version.io.zikin.centralsync-maven-plugin}
+
+ scribble
+ maven
+ scribble-java
+
+
+
+
-
- org.apache.maven.plugins
- maven-checkstyle-plugin
- 2.6
-
- checkstyle/checkstyle.xml
- false
- checkstyle/suppressions.xml
- false
-
-
-
-
- org.scribble
- build
- ${project.version}
-
-
-
-
- check-style
- site
-
- checkstyle
-
-
-
-
-
- com.mycila
- license-maven-plugin
-
-
- true
- true
-
- **/*.xml
- **/*.g
- **/*.scr
- **/*.policy
- **/*.txt
- mvnw
- mvnw.cmd
- travis/publish.sh
- .mvn/wrapper/maven-wrapper.properties
- **/Scribble-0.3.original
- **/IGNORE
- bin/*.sh
- scribblec.sh
- **/*.swp
-
- scribble-f17/**/*
-
-
-
-
-
- check
-
- compile
-
-
-
-
- maven-release-plugin
- ${version.maven-release-plugin}
-
- false
- release
- true
- @{project.version}
-
-
-
- io.zipkin.centralsync-maven-plugin
- centralsync-maven-plugin
- ${version.io.zikin.centralsync-maven-plugin}
-
- scribble
- maven
- scribble-java
-
-
-
-
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-report-plugin
+ 3.0.0-M5
+
+
+
-
-
-
- org.apache.maven.plugins
- maven-surefire-report-plugin
-
-
-
-
-
- bintray
- https://api.bintray.com/maven/scribble/maven/scribble-java/;publish=1
-
-
- jfrog-snapshots
- http://oss.jfrog.org/artifactory/oss-snapshot-local
-
-
+
+ https://github.com/scribble/scribble-java
+ scm:git:https://github.com/scribble/scribble-java.git
+
+
+ scm:git:https://github.com/scribble/scribble-java.git
+
+ HEAD
+
-
-
- release
-
-
-
-
- maven-source-plugin
- ${version.maven-source-plugin}
-
-
- attach-sources
-
- jar
-
-
-
-
-
-
- maven-javadoc-plugin
- ${version.maven-javadoc-plugin}
-
- false
-
-
-
- attach-javadocs
-
- jar
-
- package
-
-
-
-
-
-
-
+
+
+
+
+ release
+
+
+
+
+ maven-source-plugin
+ ${version.maven-source-plugin}
+
+
+ attach-sources
+
+ jar
+
+
+
+
+
+
+ maven-javadoc-plugin
+ ${version.maven-javadoc-plugin}
+
+ false
+
+
+
+ attach-javadocs
+
+ jar
+
+ package
+
+
+
+
+
+
+
diff --git a/scribble-ast/pom.xml b/scribble-ast/pom.xml
new file mode 100644
index 000000000..30b214f24
--- /dev/null
+++ b/scribble-ast/pom.xml
@@ -0,0 +1,26 @@
+
+
+ 4.0.0
+
+
+ scribble-ast
+ jar
+
+
+
+ org.scribble
+ scribble-core
+
+
+
+
+ org.scribble
+ parent
+ 0.5.1-SNAPSHOT
+
+
+
+ scribble-ast
+
+
diff --git a/scribble-ast/src/main/java/org/scribble/ast/AstFactory.java b/scribble-ast/src/main/java/org/scribble/ast/AstFactory.java
new file mode 100644
index 000000000..9507be715
--- /dev/null
+++ b/scribble-ast/src/main/java/org/scribble/ast/AstFactory.java
@@ -0,0 +1,259 @@
+/**
+ * Copyright 2008 The Scribble Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.scribble.ast;
+
+import java.util.List;
+
+import org.antlr.runtime.Token;
+import org.scribble.ast.global.GChoice;
+import org.scribble.ast.global.GConnect;
+import org.scribble.ast.global.GContinue;
+import org.scribble.ast.global.GDelegPayElem;
+import org.scribble.ast.global.GDisconnect;
+import org.scribble.ast.global.GDo;
+import org.scribble.ast.global.GInteractionSeq;
+import org.scribble.ast.global.GMsgTransfer;
+import org.scribble.ast.global.GProtoBlock;
+import org.scribble.ast.global.GProtoDecl;
+import org.scribble.ast.global.GProtoDef;
+import org.scribble.ast.global.GProtoHeader;
+import org.scribble.ast.global.GRecursion;
+import org.scribble.ast.global.GSessionNode;
+import org.scribble.ast.global.GWrap;
+import org.scribble.ast.local.LAcc;
+import org.scribble.ast.local.LChoice;
+import org.scribble.ast.local.LClientWrap;
+import org.scribble.ast.local.LContinue;
+import org.scribble.ast.local.LDisconnect;
+import org.scribble.ast.local.LDo;
+import org.scribble.ast.local.LInteractionSeq;
+import org.scribble.ast.local.LProjectionDecl;
+import org.scribble.ast.local.LProtoBlock;
+import org.scribble.ast.local.LProtoDef;
+import org.scribble.ast.local.LProtoHeader;
+import org.scribble.ast.local.LRecursion;
+import org.scribble.ast.local.LRecv;
+import org.scribble.ast.local.LReq;
+import org.scribble.ast.local.LSelfDecl;
+import org.scribble.ast.local.LSend;
+import org.scribble.ast.local.LServerWrap;
+import org.scribble.ast.local.LSessionNode;
+import org.scribble.ast.name.PayElemNameNode;
+import org.scribble.ast.name.qualified.DataNameNode;
+import org.scribble.ast.name.qualified.GProtoNameNode;
+import org.scribble.ast.name.qualified.LProtoNameNode;
+import org.scribble.ast.name.qualified.ModuleNameNode;
+import org.scribble.ast.name.qualified.SigNameNode;
+import org.scribble.ast.name.simple.AmbigNameNode;
+import org.scribble.ast.name.simple.DataParamNode;
+import org.scribble.ast.name.simple.ExtIdNode;
+import org.scribble.ast.name.simple.IdNode;
+import org.scribble.ast.name.simple.OpNode;
+import org.scribble.ast.name.simple.RecVarNode;
+import org.scribble.ast.name.simple.RoleNode;
+import org.scribble.ast.name.simple.SigParamNode;
+import org.scribble.core.type.kind.NonRoleParamKind;
+import org.scribble.core.type.kind.PayElemKind;
+
+
+// Pass null as Token t to create a fresh Token
+// AstFactory is for making "fresh" nodes ("fresh" Tokens) with new dels -- cf. ScribNode reconstruct pattern (for Token and del preservation)
+// Implementations located in scribble-parser, use ScribbleParser for Token construction
+// Currently, used only in relatively niche places (since ANTLR now constructs all parsed nodes "directly")
+public interface AstFactory
+{
+ IdNode IdNode(Token t, String text);
+ ExtIdNode ExtIdNode(Token t, String text);
+
+ AmbigNameNode AmbigNameNode(Token t, String text); // Deprecate? Never need to make ambigname "manually" via af? (constructed only by ScribbleParser)
+ DataParamNode DataParamNode(Token t, String text);
+ OpNode OpNode(Token t, String text);
+ RecVarNode RecVarNode(Token t, String text);
+ RoleNode RoleNode(Token t, String text);
+ SigParamNode SigParamNode(Token t, String text);
+
+ DataNameNode DataNameNode(Token t, List elems);
+ GProtoNameNode GProtoNameNode(Token t, List elems);
+ LProtoNameNode LProtoNameNode(Token t, List elems);
+ ModuleNameNode ModuleNameNode(Token t, List elems);
+ SigNameNode SigNameNode(Token t, List elems);
+
+ Module Module(Token t, ModuleDecl mdecl,
+ List extends ImportDecl>> imports,
+ List extends NonProtoDecl>> nonprotos,
+ List extends ProtoDecl>> protos);
+
+ ModuleDecl ModuleDecl(Token t, ModuleNameNode fullname);
+ ImportModule ImportModule(Token t, ModuleNameNode modname,
+ ModuleNameNode alias); // alias == null for no alias (child not added)
+
+ DataDecl DataDecl(Token t, IdNode schema, ExtIdNode extName,
+ ExtIdNode extSource, DataNameNode name);
+ SigDecl SigDecl(Token t, IdNode schema, ExtIdNode extName,
+ ExtIdNode extSource, SigNameNode name);
+ GProtoDecl GProtoDecl(Token t, ProtoModList mods, GProtoHeader header,
+ GProtoDef def);
+
+ // TODO: refactor to use ProtoModList, etc.
+ ProtoModList ProtoModList(Token t, List mods);
+ AuxMod AuxMod(Token t);
+ ExplicitMod ExplicitMod(Token t);
+
+ GProtoHeader GProtocolHeader(Token t, GProtoNameNode name, RoleDeclList rs,
+ NonRoleParamDeclList ps);
+ RoleDeclList RoleDeclList(Token t, List ds);
+ RoleDecl RoleDecl(Token t, RoleNode r);
+ NonRoleParamDeclList NonRoleParamDeclList(Token t,
+ List> ds);
+ DataParamDecl DataParamDecl(Token t, DataParamNode p);
+ SigParamDecl SigParamDecl(Token t, SigParamNode p);
+
+ GProtoDef GProtoDef(Token t, GProtoBlock block);
+ GProtoBlock GProtoBlock(Token t, GInteractionSeq seq);
+ GInteractionSeq GInteractionSeq(Token t, List elems); // CHECKME: ? extends GSessionNode ? -- and similar others?
+
+ SigLitNode SigLitNode(Token t, OpNode op, PayElemList pay);
+ PayElemList PayElemList(Token t, List> elems);
+ UnaryPayElem UnaryPayElem(Token t,
+ PayElemNameNode name);
+ GDelegPayElem GDelegPayElem(Token t, GProtoNameNode name, RoleNode r);
+
+ GMsgTransfer GMsgTransfer(Token t, RoleNode src, MsgNode msg,
+ List dsts);
+ GConnect GConnect(Token t, RoleNode src, MsgNode msg, RoleNode dst);
+ GDisconnect GDisconnect(Token t, RoleNode left, RoleNode right);
+ GWrap GWrap(Token t, RoleNode client, RoleNode server);
+
+ GContinue GContinue(Token t, RecVarNode rv);
+ GDo GDo(Token t, GProtoNameNode proto, NonRoleArgList args, RoleArgList rs);
+
+ RoleArgList RoleArgList(Token t, List rs);
+ RoleArg RoleArg(Token t, RoleNode r);
+ NonRoleArgList NonRoleArgList(Token t, List args);
+ NonRoleArg NonRoleArg(Token t, NonRoleArgNode arg);
+
+ GChoice GChoice(Token t, RoleNode subj, List blocks);
+ GRecursion GRecursion(Token t, RecVarNode rv, GProtoBlock block);
+
+ /*LProtoDecl LProtoDecl(Token t, ProtoModList mods,
+ LProtoHeader header, LProtoDef def); // Not currently used -- local protos not yet parsed, only projected*/
+
+ LProjectionDecl LProjectionDecl(Token t, ProtoModList mods,
+ LProtoHeader header, LProtoDef def, GProtoNameNode fullname,
+ RoleNode self); // del extends that of LProtoDecl
+
+ LProtoHeader LProtoHeader(Token t, LProtoNameNode name, RoleDeclList rs,
+ NonRoleParamDeclList ps);
+ LSelfDecl LSelfDecl(Token t, RoleNode r);
+
+ LProtoDef LProtoDef(Token t, LProtoBlock block);
+ LProtoBlock LProtoBlock(Token t, LInteractionSeq seq);
+ LInteractionSeq LInteractionSeq(Token t, List elems);
+
+ // Following take "self" param in case of parsed Token (not actually supported yet)
+ LSend LSend(Token t, RoleNode self, MsgNode msg, RoleNode dst);
+ LRecv LRecv(Token t, RoleNode src, MsgNode msg, RoleNode self);
+ LAcc LAcc(Token t, RoleNode src, MsgNode msg, RoleNode self);
+ LReq LReq(Token t, RoleNode self, MsgNode msg, RoleNode dst);
+ LDisconnect LDisconnect(Token t, RoleNode self, RoleNode peer);
+ LClientWrap LClientWrap(Token t, RoleNode client, RoleNode server);
+ LServerWrap LServerWrap(Token t, RoleNode client, RoleNode server);
+
+ LContinue LContinue(Token t, RecVarNode rv);
+ LDo LDo(Token t, LProtoNameNode proto, NonRoleArgList as, RoleArgList rs);
+
+ LChoice LChoice(Token t, RoleNode subj, List blocks);
+ LRecursion LRecursion(Token t, RecVarNode rv, LProtoBlock block);
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/*
+ DummyProjectionRoleNode DummyProjectionRoleNode();
+
+ LDelegationElem LDelegationElem(CommonTree source, LProtocolNameNode name);
+
+ LProtocolDecl LProtocolDecl(CommonTree source, List modifiers,
+ LProtocolHeader header, LProtocolDef def);
+ // Not currently used -- local protos not parsed, only projected
+
+ LProjectionDecl LProjectionDecl(CommonTree source,
+ List modifiers, GProtocolName fullname, Role self,
+ LProtocolHeader header, LProtocolDef def);
+ // del extends that of LProtocolDecl
+
+ LProtocolHeader LProtocolHeader(CommonTree source, LProtocolNameNode name,
+ RoleDeclList roledecls, NonRoleParamDeclList paramdecls);
+
+ SelfRoleDecl SelfRoleDecl(CommonTree source, RoleNode namenode);
+
+ LProtocolDef LProtocolDef(CommonTree source, LProtocolBlock block);
+
+ LProtocolBlock LProtocolBlock(CommonTree source, LInteractionSeq seq);
+
+ LInteractionSeq LInteractionSeq(CommonTree source,
+ List actions);
+
+ LSend LSend(CommonTree source, RoleNode src, MessageNode msg,
+ List dests);
+
+ LRecv LReceive(CommonTree source, RoleNode src, MessageNode msg,
+ List dests);
+
+ LRequest LRequest(CommonTree source, RoleNode src, MessageNode msg,
+ RoleNode dest);
+
+ LAccept LAccept(CommonTree source, RoleNode src, MessageNode msg,
+ RoleNode dest);
+
+ /*LConnect LConnect(CommonTree source, RoleNode src, RoleNode dest);
+ LAccept LAccept(CommonTree source, RoleNode src, RoleNode dest);* /
+
+ LDisconnect LDisconnect(CommonTree source, RoleNode self, RoleNode peer);
+
+ LWrapClient LWrapClient(CommonTree source, RoleNode self, RoleNode peer);
+
+ LWrapServer LWrapServer(CommonTree source, RoleNode self, RoleNode peer);
+
+ LChoice LChoice(CommonTree source, RoleNode subj,
+ List blocks);
+
+ LRecursion LRecursion(CommonTree source, RecVarNode recvar,
+ LProtocolBlock block);
+
+ LContinue LContinue(CommonTree source, RecVarNode recvar);
+
+ LDo LDo(CommonTree source, RoleArgList roles, NonRoleArgList args,
+ LProtocolNameNode proto);
+*/
diff --git a/scribble-ast/src/main/java/org/scribble/ast/AuxMod.java b/scribble-ast/src/main/java/org/scribble/ast/AuxMod.java
new file mode 100644
index 000000000..53fac4bb5
--- /dev/null
+++ b/scribble-ast/src/main/java/org/scribble/ast/AuxMod.java
@@ -0,0 +1,65 @@
+/**
+ * Copyright 2008 The Scribble Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.scribble.ast;
+
+import org.antlr.runtime.Token;
+import org.scribble.del.DelFactory;
+
+public class AuxMod extends ProtoModNode
+{
+ // ScribTreeAdaptor#create constructor
+ public AuxMod(Token t)
+ {
+ super(t);
+ }
+
+ // Tree#dupNode constructor
+ protected AuxMod(AuxMod node)
+ {
+ super(node);
+ }
+
+ @Override
+ public AuxMod dupNode()
+ {
+ return new AuxMod(this); // return this also OK, since no children
+ }
+
+ @Override
+ public void decorateDel(DelFactory df)
+ {
+ df.AuxMod(this);
+ }
+
+ @Override
+ public boolean isAux()
+ {
+ return true;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "aux";
+ }
+
+
+
+
+
+
+
+
+ public static final AuxMod AUX = new AuxMod((Token) null);
+}
diff --git a/scribble-ast/src/main/java/org/scribble/ast/BasicInteraction.java b/scribble-ast/src/main/java/org/scribble/ast/BasicInteraction.java
new file mode 100644
index 000000000..a205e8f77
--- /dev/null
+++ b/scribble-ast/src/main/java/org/scribble/ast/BasicInteraction.java
@@ -0,0 +1,34 @@
+/**
+ * Copyright 2008 The Scribble Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.scribble.ast;
+
+import org.antlr.runtime.Token;
+import org.scribble.core.type.kind.ProtoKind;
+
+public abstract class BasicInteraction
+ extends SimpleSessionNode
+{
+ // ScribTreeAdaptor#create constructor
+ public BasicInteraction(Token t)
+ {
+ super(t);
+ }
+
+ // Tree#dupNode constructor
+ public BasicInteraction(BasicInteraction node)
+ {
+ super(node);
+ }
+}
+
diff --git a/scribble-ast/src/main/java/org/scribble/ast/Choice.java b/scribble-ast/src/main/java/org/scribble/ast/Choice.java
new file mode 100644
index 000000000..1823047fb
--- /dev/null
+++ b/scribble-ast/src/main/java/org/scribble/ast/Choice.java
@@ -0,0 +1,91 @@
+/**
+ * Copyright 2008 The Scribble Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.scribble.ast;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.antlr.runtime.Token;
+import org.scribble.ast.name.simple.RoleNode;
+import org.scribble.core.type.kind.ProtoKind;
+import org.scribble.util.Constants;
+import org.scribble.util.ScribException;
+import org.scribble.visit.AstVisitor;
+
+public abstract class Choice
+ extends CompoundInteraction
+{
+ public static final int SUBJ_CHILD_INDEX = 0;
+ public static final int BLOCK_CHILDREN_START_INDEX = 1;
+
+ // ScribTreeAdaptor#create constructor
+ public Choice(Token t)
+ {
+ super(t);
+ }
+
+ // Tree#dupNode constructor
+ protected Choice(Choice node)
+ {
+ super(node);
+ }
+
+ public RoleNode getSubjectChild()
+ {
+ return (RoleNode) getChild(SUBJ_CHILD_INDEX);
+ }
+
+ // Override in concrete sub for cast
+ public abstract List extends ProtoBlock> getBlockChildren();
+
+ // "add", not "set"
+ public void addScribChildren(RoleNode subj,
+ List extends ProtoBlock> blocks)
+ {
+ // Cf. above getters and Scribble.g children order
+ addChild(subj);
+ addChildren(blocks);
+ }
+
+ @Override
+ public abstract Choice dupNode();
+
+ public Choice reconstruct(RoleNode subj,
+ List extends ProtoBlock> blocks)
+ {
+ Choice dup = dupNode();
+ dup.addScribChildren(subj, blocks);
+ dup.setDel(del()); // No copy
+ return dup;
+ }
+
+ @Override
+ public Choice visitChildren(AstVisitor nv) throws ScribException
+ {
+ RoleNode subj = (RoleNode) visitChild(getSubjectChild(), nv);
+ List extends ProtoBlock> blocks =
+ visitChildListWithClassEqualityCheck(this, getBlockChildren(), nv);
+ return reconstruct(subj, blocks);
+ }
+
+ @Override
+ public String toString()
+ {
+ String sep = " " + Constants.OR_KW + " ";
+ return Constants.CHOICE_KW + " "
+ + Constants.AT_KW + " " + getSubjectChild() + " "
+ + getBlockChildren().stream().map(b -> b.toString())
+ .collect(Collectors.joining(sep));
+ }
+}
diff --git a/scribble-ast/src/main/java/org/scribble/ast/CompoundInteraction.java b/scribble-ast/src/main/java/org/scribble/ast/CompoundInteraction.java
new file mode 100644
index 000000000..716948b1b
--- /dev/null
+++ b/scribble-ast/src/main/java/org/scribble/ast/CompoundInteraction.java
@@ -0,0 +1,33 @@
+/**
+ * Copyright 2008 The Scribble Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.scribble.ast;
+
+import org.antlr.runtime.Token;
+import org.scribble.core.type.kind.ProtoKind;
+
+public abstract class CompoundInteraction
+ extends CompoundSessionNode
+{
+ // ScribTreeAdaptor#create constructor
+ public CompoundInteraction(Token t)
+ {
+ super(t);
+ }
+
+ // Tree#dupNode constructor
+ protected CompoundInteraction(CompoundInteraction node)
+ {
+ super(node);
+ }
+}
diff --git a/scribble-ast/src/main/java/org/scribble/ast/CompoundSessionNode.java b/scribble-ast/src/main/java/org/scribble/ast/CompoundSessionNode.java
new file mode 100644
index 000000000..f320a43da
--- /dev/null
+++ b/scribble-ast/src/main/java/org/scribble/ast/CompoundSessionNode.java
@@ -0,0 +1,34 @@
+/**
+ * Copyright 2008 The Scribble Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.scribble.ast;
+
+import org.antlr.runtime.Token;
+import org.scribble.core.type.kind.ProtoKind;
+
+// Redundant? Is always a CompoundInteraction -- cf. SimpleSessionNode
+public abstract class CompoundSessionNode
+ extends ScribNodeBase implements SessionNode
+{
+ // ScribTreeAdaptor#create constructor
+ public CompoundSessionNode(Token t)
+ {
+ super(t);
+ }
+
+ // Tree#dupNode constructor
+ protected CompoundSessionNode(CompoundSessionNode node)
+ {
+ super(node);
+ }
+}
diff --git a/scribble-ast/src/main/java/org/scribble/ast/ConnectAction.java b/scribble-ast/src/main/java/org/scribble/ast/ConnectAction.java
new file mode 100644
index 000000000..37c64dcfc
--- /dev/null
+++ b/scribble-ast/src/main/java/org/scribble/ast/ConnectAction.java
@@ -0,0 +1,61 @@
+/**
+ * Copyright 2008 The Scribble Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.scribble.ast;
+
+import java.util.List;
+
+import org.antlr.runtime.Token;
+import org.scribble.ast.name.simple.RoleNode;
+import org.scribble.core.type.kind.ProtoKind;
+
+// TODO CHECKME: factor with MessageTransfer?
+public abstract class ConnectAction
+ extends DirectedInteraction
+{
+ // ScribTreeAdaptor#create constructor
+ public ConnectAction(Token t)
+ {
+ super(t);
+ }
+
+ // Tree#dupNode constructor
+ public ConnectAction(ConnectAction node)
+ {
+ super(node);
+ }
+
+ // TODO: refactor
+ public RoleNode getDestinationChild()
+ {
+ List dests = getDestinationChildren();
+ if (dests.size() != 1)
+ {
+ throw new RuntimeException("Shouldn't get in here: " + this);
+ // CHECKME: don't use common src/dst pattern between global/local?
+ }
+ return dests.get(0);
+ }
+
+ // CHECKME: currently only used for toString, because current syntax allows "connect" with no explicit message ?
+ protected boolean isUnitMessage()
+ {
+ MsgNode n = getMessageNodeChild();
+ if (!n.isSigLitNode())
+ {
+ return false;
+ }
+ SigLitNode msn = (SigLitNode) n;
+ return msn.getOpChild().isEmpty() && msn.getPayloadListChild().isEmpty();
+ }
+}
diff --git a/scribble-ast/src/main/java/org/scribble/ast/Continue.java b/scribble-ast/src/main/java/org/scribble/ast/Continue.java
new file mode 100644
index 000000000..f64dd6eb6
--- /dev/null
+++ b/scribble-ast/src/main/java/org/scribble/ast/Continue.java
@@ -0,0 +1,74 @@
+/**
+ * Copyright 2008 The Scribble Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.scribble.ast;
+
+import org.antlr.runtime.Token;
+import org.scribble.ast.name.simple.RecVarNode;
+import org.scribble.core.type.kind.ProtoKind;
+import org.scribble.util.Constants;
+import org.scribble.util.ScribException;
+import org.scribble.visit.AstVisitor;
+
+public abstract class Continue
+ extends SimpleSessionNode
+{
+ public static final int RECVAR_CHILD_INDEX = 0;
+
+ // ScribTreeAdaptor#create constructor
+ public Continue(Token t)
+ {
+ super(t);
+ }
+
+ // Tree#dupNode constructor
+ protected Continue(Continue node)
+ {
+ super(node);
+ }
+
+ // "add", not "set"
+ public void addScribChildren(RecVarNode rv)
+ {
+ // Cf. above getters and Scribble.g children order
+ addChild(rv);
+ }
+
+ public abstract Continue dupNode();
+
+ public RecVarNode getRecVarChild()
+ {
+ return (RecVarNode) getChild(RECVAR_CHILD_INDEX);
+ }
+
+ public Continue reconstruct(RecVarNode rv)
+ {
+ Continue dup = dupNode();
+ dup.addScribChildren(rv);
+ dup.setDel(del()); // No copy
+ return dup;
+ }
+
+ @Override
+ public Continue visitChildren(AstVisitor nv) throws ScribException
+ {
+ RecVarNode recvar = (RecVarNode) visitChild(getRecVarChild(), nv);
+ return reconstruct(recvar);
+ }
+
+ @Override
+ public String toString()
+ {
+ return Constants.CONTINUE_KW + " " + getRecVarChild() + ";";
+ }
+}
diff --git a/scribble-ast/src/main/java/org/scribble/ast/DataDecl.java b/scribble-ast/src/main/java/org/scribble/ast/DataDecl.java
new file mode 100644
index 000000000..56f5f59e0
--- /dev/null
+++ b/scribble-ast/src/main/java/org/scribble/ast/DataDecl.java
@@ -0,0 +1,86 @@
+/**
+ * Copyright 2008 The Scribble Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.scribble.ast;
+
+import org.antlr.runtime.Token;
+import org.scribble.ast.name.qualified.DataNameNode;
+import org.scribble.core.type.kind.DataKind;
+import org.scribble.core.type.name.DataName;
+import org.scribble.core.type.name.ModuleName;
+import org.scribble.del.DelFactory;
+import org.scribble.util.Constants;
+
+public class DataDecl extends NonProtoDecl
+{
+ // ScribTreeAdaptor#create constructor
+ public DataDecl(Token payload)
+ {
+ super(payload);
+ }
+
+ // Tree#dupNode constructor
+ protected DataDecl(DataDecl node)
+ {
+ super(node);
+ }
+
+ @Override
+ public DataNameNode getNameNodeChild()
+ {
+ return (DataNameNode) getRawNameNodeChild();
+ }
+
+ // Cf. CommonTree#dupNode
+ @Override
+ public DataDecl dupNode()
+ {
+ return new DataDecl(this);
+ }
+
+ @Override
+ public void decorateDel(DelFactory df)
+ {
+ df.DataDecl(this);
+ }
+
+ @Override
+ public boolean isDataDecl()
+ {
+ return true;
+ }
+
+ // Simple name (ModuleDecl is the only NameDeclNode that uses qualified names)
+ @Override
+ public DataName getDeclName()
+ {
+ return getNameNodeChild().toName();
+ }
+
+ @Override
+ public DataName getFullMemberName(Module mod)
+ {
+ ModuleName fullmodname = mod.getFullModuleName();
+ return new DataName(fullmodname, getDeclName());
+ }
+
+ @Override
+ public String toString()
+ {
+ return Constants.DATA_KW + " <" + getSchemaChild() + "> "
+ + getExtNameChild() + " "
+ + Constants.FROM_KW + " " + getExtSourceChild() + " "
+ + Constants.AS_KW + " " + getDeclName()
+ + ";";
+ }
+}
diff --git a/scribble-ast/src/main/java/org/scribble/ast/DataParamDecl.java b/scribble-ast/src/main/java/org/scribble/ast/DataParamDecl.java
new file mode 100644
index 000000000..732edec8b
--- /dev/null
+++ b/scribble-ast/src/main/java/org/scribble/ast/DataParamDecl.java
@@ -0,0 +1,66 @@
+/**
+ * Copyright 2008 The Scribble Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.scribble.ast;
+
+import org.antlr.runtime.Token;
+import org.scribble.ast.name.simple.DataParamNode;
+import org.scribble.core.type.kind.DataKind;
+import org.scribble.core.type.name.DataName;
+import org.scribble.del.DelFactory;
+import org.scribble.util.Constants;
+
+public class DataParamDecl extends NonRoleParamDecl
+{
+ // ScribTreeAdaptor#create constructor
+ public DataParamDecl(Token t)
+ {
+ super(t, DataKind.KIND);
+ }
+
+ // Tree#dupNode constructor
+ public DataParamDecl(DataParamDecl node)
+ {
+ super(node);
+ }
+
+ @Override
+ public DataParamNode getNameNodeChild()
+ {
+ return (DataParamNode) getRawNameNodeChild();
+ }
+
+ @Override
+ public DataParamDecl dupNode()
+ {
+ return new DataParamDecl(this);
+ }
+
+ @Override
+ public void decorateDel(DelFactory df)
+ {
+ df.DataParamDecl(this);
+ }
+
+ @Override
+ public DataName getDeclName()
+ {
+ return (DataName) getNameNodeChild().toName();
+ }
+
+ @Override
+ public String getKeyword()
+ {
+ return Constants.DATA_KW;
+ }
+}
diff --git a/scribble-ast/src/main/java/org/scribble/ast/DirectedInteraction.java b/scribble-ast/src/main/java/org/scribble/ast/DirectedInteraction.java
new file mode 100644
index 000000000..2b3eeda06
--- /dev/null
+++ b/scribble-ast/src/main/java/org/scribble/ast/DirectedInteraction.java
@@ -0,0 +1,101 @@
+/**
+ * Copyright 2008 The Scribble Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.scribble.ast;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.antlr.runtime.Token;
+import org.scribble.ast.name.simple.RoleNode;
+import org.scribble.core.type.kind.ProtoKind;
+import org.scribble.core.type.name.Role;
+import org.scribble.util.ScribException;
+import org.scribble.visit.AstVisitor;
+
+// FIXME: rename (Simple)Interaction, after existing SimpleInteraction renamed
+public abstract class DirectedInteraction
+ extends BasicInteraction
+{
+ public static final int MSG_CHILD_INDEX = 0;
+ public static final int SRC_CHILD_INDEX = 1;
+ public static final int DST_CHILDREN_START_INDEX = 2;
+
+ // ScribTreeAdaptor#create constructor
+ public DirectedInteraction(Token t)
+ {
+ super(t);
+ }
+
+ // Tree#dupNode constructor
+ public DirectedInteraction(DirectedInteraction node)
+ {
+ super(node);
+ }
+
+ public MsgNode getMessageNodeChild()
+ {
+ return (MsgNode) getChild(MSG_CHILD_INDEX);
+ }
+
+ public RoleNode getSourceChild()
+ {
+ return (RoleNode) getChild(SRC_CHILD_INDEX);
+ }
+
+ public List getDestinationChildren()
+ {
+ List extends ScribNode> cs = getChildren();
+ return cs.subList(DST_CHILDREN_START_INDEX, cs.size()).stream()
+ .map(x -> (RoleNode) x).collect(Collectors.toList());
+ }
+
+ public final List getDestinationRoles()
+ {
+ return getDestinationChildren().stream().map(rn -> rn.toName())
+ .collect(Collectors.toList());
+ }
+
+ // "add", not "set"
+ public void addScribChildren(MsgNode msg, RoleNode src, List dsts)
+ {
+ // Cf. above getters and Scribble.g children order
+ addChild(msg);
+ addChild(src);
+ addChildren(dsts);
+ }
+
+ public abstract DirectedInteraction dupNode();
+
+ public DirectedInteraction reconstruct(MsgNode msg, RoleNode src,
+ List dsts)
+ {
+ DirectedInteraction dup = dupNode();
+ // Same order as getter indices
+ dup.addScribChildren(msg, src, dsts);
+ dup.setDel(del()); // No copy
+ return dup;
+ }
+
+ @Override
+ public DirectedInteraction visitChildren(AstVisitor nv)
+ throws ScribException
+ {
+ MsgNode msg = (MsgNode) visitChild(getMessageNodeChild(), nv);
+ RoleNode src = (RoleNode) visitChild(getSourceChild(), nv);
+ List dests = visitChildListWithClassEqualityCheck(this,
+ getDestinationChildren(), nv);
+ return reconstruct(msg, src, dests);
+ }
+}
+
diff --git a/scribble-ast/src/main/java/org/scribble/ast/DisconnectAction.java b/scribble-ast/src/main/java/org/scribble/ast/DisconnectAction.java
new file mode 100644
index 000000000..2d4befc1d
--- /dev/null
+++ b/scribble-ast/src/main/java/org/scribble/ast/DisconnectAction.java
@@ -0,0 +1,86 @@
+/**
+ * Copyright 2008 The Scribble Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.scribble.ast;
+
+import org.antlr.runtime.Token;
+import org.scribble.ast.name.simple.RoleNode;
+import org.scribble.core.type.kind.ProtoKind;
+import org.scribble.util.Constants;
+import org.scribble.util.ScribException;
+import org.scribble.visit.AstVisitor;
+
+// (G)Disconnect is symmetric (send/receive asymmetric/async; request/accept asymmetric/sync; (g)disconnect symmetric/async)
+// However, LDisconnect is "symmetric" but self-oriented -- "left" used for self
+public abstract class DisconnectAction
+ extends BasicInteraction
+{
+ public static final int LEFT_CHILD_INDEX = 0;
+ public static final int RIGHT_CHILD_INDEX = 1;
+
+ // ScribTreeAdaptor#create constructor
+ public DisconnectAction(Token t)
+ {
+ super(t);
+ }
+
+ // Tree#dupNode constructor
+ public DisconnectAction(DisconnectAction node)
+ {
+ super(node);
+ }
+
+ public RoleNode getLeftChild()
+ {
+ return (RoleNode) getChild(LEFT_CHILD_INDEX);
+ }
+
+ public RoleNode getRightChild()
+ {
+ return (RoleNode) getChild(RIGHT_CHILD_INDEX);
+ }
+
+ // "add", not "set"
+ public void addScribChildren(RoleNode left, RoleNode right)
+ {
+ // Cf. above getters and Scribble.g children order
+ addChild(left);
+ addChild(right);
+ }
+
+ public abstract DisconnectAction dupNode();
+
+ public DisconnectAction reconstruct(RoleNode left, RoleNode right)
+ {
+ DisconnectAction dup = dupNode();
+ dup.addScribChildren(left, right);
+ dup.setDel(del()); // No copy
+ return dup;
+ }
+
+ @Override
+ public DisconnectAction visitChildren(AstVisitor nv)
+ throws ScribException
+ {
+ RoleNode src = (RoleNode) visitChild(getLeftChild(), nv);
+ RoleNode dest = (RoleNode) visitChild(getRightChild(), nv);
+ return reconstruct(src, dest);
+ }
+
+ @Override
+ public String toString()
+ {
+ return Constants.DISCONNECT_KW + " " + getLeftChild()
+ + " " + Constants.AND_KW + " " + getRightChild() + ";";
+ }
+}
diff --git a/scribble-ast/src/main/java/org/scribble/ast/Do.java b/scribble-ast/src/main/java/org/scribble/ast/Do.java
new file mode 100644
index 000000000..36d60cbbe
--- /dev/null
+++ b/scribble-ast/src/main/java/org/scribble/ast/Do.java
@@ -0,0 +1,130 @@
+/**
+ * Copyright 2008 The Scribble Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.scribble.ast;
+
+import java.util.Iterator;
+
+import org.antlr.runtime.Token;
+import org.scribble.ast.name.qualified.ProtoNameNode;
+import org.scribble.core.lang.context.ModuleContext;
+import org.scribble.core.type.kind.ProtoKind;
+import org.scribble.core.type.name.ProtoName;
+import org.scribble.core.type.name.Role;
+import org.scribble.job.JobContext;
+import org.scribble.util.Constants;
+import org.scribble.util.ScribException;
+import org.scribble.visit.AstVisitor;
+
+public abstract class Do
+ extends SimpleSessionNode // implements ScopedNode
+{
+ public static final int NAME_CHILD_INDEX = 0;
+ public static final int ARG_LIST_CHILD_INDEX = 1;
+ public static final int ROLE_LIST_CHILD_INDEX = 2;
+
+ // ScribTreeAdaptor#create constructor
+ public Do(Token t)
+ {
+ super(t);
+ }
+
+ // Tree#dupNode constructor
+ public Do(Do node)
+ {
+ super(node);
+ }
+
+ public abstract ProtoNameNode getProtocolNameNode();
+
+ public NonRoleArgList getNonRoleListChild()
+ {
+ return (NonRoleArgList) getChild(ARG_LIST_CHILD_INDEX);
+ }
+
+ // CHECKME: maybe wrap up role args and non-role args within the same container?
+ public RoleArgList getRoleListChild()
+ {
+ return (RoleArgList) getChild(ROLE_LIST_CHILD_INDEX);
+ }
+
+ // "add", not "set"
+ public void addScribChildren(ProtoNameNode proto, NonRoleArgList as,
+ RoleArgList rs)
+ {
+ // Cf. above getters and Scribble.g children order
+ addChild(proto); // Order re. getter indices
+ addChild(as);
+ addChild(rs);
+ }
+
+ public abstract Do dupNode();
+
+ public Do reconstruct(ProtoNameNode proto, NonRoleArgList as,
+ RoleArgList rs)
+ {
+ Do dup = dupNode();
+ dup.addScribChildren(proto, as, rs);
+ dup.setDel(del()); // No copy
+ return dup;
+ }
+
+ @Override
+ public Do visitChildren(AstVisitor nv) throws ScribException
+ {
+ RoleArgList ril = (RoleArgList) visitChild(getRoleListChild(), nv);
+ NonRoleArgList al = (NonRoleArgList) visitChild(getNonRoleListChild(), nv);
+ ProtoNameNode proto = visitChildWithClassEqualityCheck(this,
+ getProtocolNameNode(), nv);
+ return reconstruct(proto, al, ril);
+ }
+
+ // FIXME: mcontext now redundant because NameDisambiguator converts all targets to full names -- NO: currently disamb doesn't
+ // To get full name from original target name, use mcontext visible names (e.g. in or before name disambiguation pass)
+ // This is still useful for subclass casting to G/LProtocolName
+ public ProtoName getTargetProtoDeclFullName(ModuleContext mcontext)
+ {
+ //return mcontext.checkProtocolDeclDependencyFullName(this.proto.toName());
+ return getProtocolNameNode().toName(); // Pre: use after name disambiguation (maybe drop FullName suffix)
+ }
+
+ // CHECKME: mcontext redundant, because redundant for getTargetProtocolDeclFullName
+ public abstract ProtoDecl getTargetProtocolDecl(JobContext jcontext,
+ ModuleContext mcontext);
+
+ public Role getTargetRoleParameter(JobContext jcontext,
+ ModuleContext mcontext, Role role)
+ {
+ Iterator args = getRoleListChild().getRoles().iterator();
+ Iterator params = getTargetProtocolDecl(jcontext, mcontext)
+ .getHeaderChild().getRoleDeclListChild().getRoles().iterator();
+ while (args.hasNext())
+ {
+ Role arg = args.next();
+ Role param = params.next();
+ if (arg.equals(role))
+ {
+ return param;
+ }
+ }
+ throw new RuntimeException("Not an argument role: " + role);
+ }
+
+ @Override
+ public String toString()
+ {
+ String s = Constants.DO_KW + " ";
+ return s + getProtocolNameNode() + getNonRoleListChild() + getRoleListChild()
+ + ";";
+ }
+}
diff --git a/scribble-ast/src/main/java/org/scribble/ast/DoArg.java b/scribble-ast/src/main/java/org/scribble/ast/DoArg.java
new file mode 100644
index 000000000..cd063a8c3
--- /dev/null
+++ b/scribble-ast/src/main/java/org/scribble/ast/DoArg.java
@@ -0,0 +1,76 @@
+/**
+ * Copyright 2008 The Scribble Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.scribble.ast;
+
+import org.antlr.runtime.Token;
+import org.scribble.util.ScribException;
+import org.scribble.visit.AstVisitor;
+
+// TODO: rename better? DoArg, DoArgNode, ...
+// CHECKME: make DoArg into an interface and have DoArgNode as direct children of Do?
+// Cf. NameDeclNode/HeaderParameterDecl, i.e. wrappers for param names/arg values
+// Simpler than NameDeclNode, doesn't constrain node-type correspondence for names
+public abstract class DoArg extends ScribNodeBase
+{
+ // ScribTreeAdaptor#create constructor
+ public DoArg(Token t)
+ {
+ super(t);
+ }
+
+ // Tree#dupNode constructor
+ public DoArg(DoArg node)
+ {
+ super(node);
+ }
+
+ public abstract T getArgNodeChild();
+
+ // "add", not "set"
+ public void addScribChildren(T arg)
+ {
+ // Cf. above getters and Scribble.g children order
+ addChild(arg);
+ }
+
+ public abstract DoArg dupNode();
+
+ public DoArg reconstruct(T arg)
+ {
+ DoArg dup = dupNode();
+ dup.addScribChildren(arg);
+ dup.setDel(del()); // No copy
+ return dup;
+ }
+
+ @Override
+ public DoArg visitChildren(AstVisitor nv) throws ScribException
+ {
+ ScribNode visited = visitChild(getArgNodeChild(), nv); // Disambiguation will replace AmbiguousNameNodes
+ // CHECKME: use visitChildWithClassEqualityCheck?
+ if (!(visited instanceof DoArgNode))
+ {
+ throw new RuntimeException("Shouldn't get in here: " + visited);
+ }
+ @SuppressWarnings("unchecked")
+ T arg = (T) visited;
+ return reconstruct(arg);
+ }
+
+ @Override
+ public String toString()
+ {
+ return getArgNodeChild().toString();
+ }
+}
diff --git a/scribble-ast/src/main/java/org/scribble/ast/DoArgList.java b/scribble-ast/src/main/java/org/scribble/ast/DoArgList.java
new file mode 100644
index 000000000..daccb7251
--- /dev/null
+++ b/scribble-ast/src/main/java/org/scribble/ast/DoArgList.java
@@ -0,0 +1,85 @@
+/**
+ * Copyright 2008 The Scribble Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.scribble.ast;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.antlr.runtime.Token;
+import org.scribble.util.ScribException;
+import org.scribble.visit.AstVisitor;
+
+// Cf. HeaderParameterDeclList -- but not kinded, because cannot determine Arg kind directly from node syntax itself (kinding for ModelNodes is to supplement syntactic information, not "typing" work)
+// DoArgList (NonRoleArgList) can be of mixed kinds, so DoArg (NonRoleArg) used as "wildcard" wrapper
+// "? extends InstantiationNode" not enforced here (e.g. can put "? extends ModelNode"), because ultimately any instantiation of this class needs an actual instance of "Instantiation" which has to have a parameter that extends "InstantiationNode"
+public abstract class DoArgList> extends ScribNodeBase
+{
+ // ScribTreeAdaptor#create constructor
+ public DoArgList(Token t)
+ {
+ super(t);
+ }
+
+ // Tree#dupNode constructor
+ public DoArgList(DoArgList node)
+ {
+ super(node);
+ }
+
+ protected List extends ScribNode> getRawArgChildren()
+ {
+ return getChildren();
+ }
+
+ public abstract List getArgChildren();
+
+ // "add", not "set"
+ public void addScribChildren(List args)
+ {
+ // Cf. above getters and Scribble.g children order
+ addChildren(args);
+ }
+
+ @Override
+ public abstract DoArgList dupNode();
+
+ public DoArgList reconstruct(List args)
+ {
+ DoArgList dup = dupNode();
+ dup.addScribChildren(args);
+ dup.setDel(del()); // No copy
+ return dup;
+ }
+
+ @Override
+ public DoArgList visitChildren(AstVisitor nv) throws ScribException
+ {
+ List nds =
+ visitChildListWithClassEqualityCheck(this, getArgChildren(), nv);
+ return reconstruct(nds);
+ }
+
+ public int length()
+ {
+ return getChildCount();
+ }
+
+ // Like HeaderParamDeclList, without enclosing braces -- added by subclasses
+ @Override
+ public String toString()
+ {
+ return getArgChildren().stream().map(a -> a.toString())
+ .collect(Collectors.joining(", "));
+ }
+}
diff --git a/scribble-core/src/main/java/org/scribble/ast/DoArgNode.java b/scribble-ast/src/main/java/org/scribble/ast/DoArgNode.java
similarity index 100%
rename from scribble-core/src/main/java/org/scribble/ast/DoArgNode.java
rename to scribble-ast/src/main/java/org/scribble/ast/DoArgNode.java
diff --git a/scribble-ast/src/main/java/org/scribble/ast/ExplicitMod.java b/scribble-ast/src/main/java/org/scribble/ast/ExplicitMod.java
new file mode 100644
index 000000000..82cdb2470
--- /dev/null
+++ b/scribble-ast/src/main/java/org/scribble/ast/ExplicitMod.java
@@ -0,0 +1,56 @@
+/**
+ * Copyright 2008 The Scribble Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.scribble.ast;
+
+import org.antlr.runtime.Token;
+import org.scribble.del.DelFactory;
+
+public class ExplicitMod extends ProtoModNode
+{
+ // ScribTreeAdaptor#create constructor
+ public ExplicitMod(Token t)
+ {
+ super(t);
+ }
+
+ // Tree#dupNode constructor
+ protected ExplicitMod(ExplicitMod node)
+ {
+ super(node);
+ }
+
+ @Override
+ public boolean isExplicit()
+ {
+ return true;
+ }
+
+ @Override
+ public ExplicitMod dupNode()
+ {
+ return new ExplicitMod(this); // return this also OK, since no children
+ }
+
+ @Override
+ public void decorateDel(DelFactory df)
+ {
+ df.ExplicitMod(this);
+ }
+
+ @Override
+ public String toString()
+ {
+ return "explicit";
+ }
+}
diff --git a/scribble-ast/src/main/java/org/scribble/ast/ImportDecl.java b/scribble-ast/src/main/java/org/scribble/ast/ImportDecl.java
new file mode 100644
index 000000000..331a3155a
--- /dev/null
+++ b/scribble-ast/src/main/java/org/scribble/ast/ImportDecl.java
@@ -0,0 +1,45 @@
+/**
+ * Copyright 2008 The Scribble Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.scribble.ast;
+
+import org.antlr.runtime.Token;
+import org.scribble.core.type.kind.ImportKind;
+import org.scribble.core.type.name.Name;
+
+// CHECKME: factor out more stuff from ImportModule and ImportMember into here? e.g. alias/name, reconstruct (or else no need for common super?)
+public abstract class ImportDecl extends ScribNodeBase
+{
+ // ScribTreeAdaptor#create constructor
+ public ImportDecl(Token payload)
+ {
+ super(payload);
+ }
+
+ // Tree#dupNode constructor
+ protected ImportDecl(ImportDecl node)
+ {
+ super(node);
+ }
+
+ public abstract ImportDecl dupNode();
+
+ public boolean isImportModule()
+ {
+ return false;
+ }
+
+ public abstract boolean hasAlias();
+
+ public abstract Name getAlias();
+}
diff --git a/scribble-ast/src/main/java/org/scribble/ast/ImportModule.java b/scribble-ast/src/main/java/org/scribble/ast/ImportModule.java
new file mode 100644
index 000000000..b7af51c3d
--- /dev/null
+++ b/scribble-ast/src/main/java/org/scribble/ast/ImportModule.java
@@ -0,0 +1,128 @@
+/**
+ * Copyright 2008 The Scribble Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.scribble.ast;
+
+import org.antlr.runtime.Token;
+import org.scribble.ast.name.qualified.ModuleNameNode;
+import org.scribble.core.type.kind.ModuleKind;
+import org.scribble.core.type.name.ModuleName;
+import org.scribble.del.DelFactory;
+import org.scribble.util.Constants;
+import org.scribble.util.ScribException;
+import org.scribble.visit.AstVisitor;
+
+public class ImportModule extends ImportDecl
+{
+ public static final int MODULENAME_CHILD = 0;
+ public static final int ALIAS_CHILD = 1;
+
+ // ScribTreeAdaptor#create constructor
+ public ImportModule(Token payload)
+ {
+ super(payload);
+ }
+
+ // Tree#dupNode constructor
+ protected ImportModule(ImportModule node)
+ {
+ super(node);
+ }
+
+ // Full name ("import x.y.Z")
+ public ModuleNameNode getModuleNameNodeChild()
+ {
+ return (ModuleNameNode) getChild(MODULENAME_CHILD);
+ }
+
+ // Pre: hasAlias -- no alias means no child
+ // Simple name
+ // No child if no alias (cf. hasAlias) -- cf. addScribChildren, alias == null
+ public ModuleNameNode getAliasNameNodeChild()
+ {
+ return (ModuleNameNode) getChild(ALIAS_CHILD);
+ }
+
+ // "add", not "set"
+ public void addScribChildren(ModuleNameNode modname, ModuleNameNode alias)
+ {
+ // Cf. above getters and Scribble.g children order
+ addChild(modname);
+ if (alias != null)
+ {
+ addChild(alias);
+ }
+ }
+
+ // Cf. CommonTree#dupNode
+ @Override
+ public ImportModule dupNode()
+ {
+ return new ImportModule(this);
+ }
+
+ @Override
+ public void decorateDel(DelFactory df)
+ {
+ df.ImportModule(this);
+ }
+
+ // alias == null if no alias
+ public ImportModule reconstruct(ModuleNameNode modname, ModuleNameNode alias)
+ {
+ ImportModule dup = dupNode();
+ dup.addScribChildren(modname, alias);
+ dup.setDel(del()); // No copy
+ return dup;
+ }
+
+ @Override
+ public ImportModule visitChildren(AstVisitor nv) throws ScribException
+ {
+ ModuleNameNode modname = (ModuleNameNode)
+ visitChild(getModuleNameNodeChild(), nv);
+ ModuleNameNode alias = hasAlias()
+ ? (ModuleNameNode) visitChild(getAliasNameNodeChild(), nv)
+ : null;
+ return reconstruct(modname, alias);
+ }
+
+ @Override
+ public boolean isImportModule()
+ {
+ return true;
+ }
+
+ @Override
+ public boolean hasAlias()
+ {
+ return getChildCount() > 1;
+ }
+
+ @Override
+ public ModuleName getAlias()
+ {
+ return getAliasNameNodeChild().toName();
+ }
+
+ @Override
+ public String toString()
+ {
+ String s = Constants.IMPORT_KW + " " + getModuleNameNodeChild();
+ if (hasAlias())
+ {
+ s += " " + Constants.AS_KW + " " + getAlias();
+ }
+ return s + ";";
+ }
+}
diff --git a/scribble-ast/src/main/java/org/scribble/ast/InteractionSeq.java b/scribble-ast/src/main/java/org/scribble/ast/InteractionSeq.java
new file mode 100644
index 000000000..60477d36f
--- /dev/null
+++ b/scribble-ast/src/main/java/org/scribble/ast/InteractionSeq.java
@@ -0,0 +1,97 @@
+/**
+ * Copyright 2008 The Scribble Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.scribble.ast;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.antlr.runtime.Token;
+import org.scribble.core.type.kind.ProtoKind;
+import org.scribble.util.ScribException;
+import org.scribble.visit.AstVisitor;
+
+public abstract class InteractionSeq
+ extends ScribNodeBase implements ProtoKindNode
+{
+ // ScribTreeAdaptor#create constructor
+ public InteractionSeq(Token t)
+ {
+ super(t);
+ }
+
+ // Tree#dupNode constructor
+ public InteractionSeq(InteractionSeq node)
+ {
+ super(node);
+ }
+
+ public abstract List extends SessionNode> getInteractionChildren();
+
+ // "add", not "set"
+ public void addScribChildren(List extends SessionNode> elems)
+ {
+ // Cf. above getters and Scribble.g children order
+ addChildren(elems);
+ }
+
+ @Override
+ public abstract InteractionSeq dupNode();
+
+ public InteractionSeq reconstruct(List extends SessionNode> elems)
+ {
+ InteractionSeq dup = dupNode();
+ dup.addScribChildren(elems);
+ dup.setDel(del()); // No copy
+ return dup;
+ }
+
+ @Override
+ public ScribNode visitChildren(AstVisitor nv) throws ScribException
+ {
+ List> actions = new LinkedList<>();
+ for (SessionNode in : getInteractionChildren())
+ {
+ //ProtocolKindNode visited = visitProtocolKindChildWithCastCheck(this, in, nv, ProtocolKindNode.class, in.getKind(), KIND_CAST);
+ // No: ProjectedChoiceDoPruning (and others?) needs to return null; CastCheck doesn't allow that // CHECKME
+ // TODO: make a unit test for this
+ ScribNode visited = visitChild(in, nv);
+ if (visited instanceof InteractionSeq>)
+ {
+ @SuppressWarnings("unchecked")
+ InteractionSeq tmp = (InteractionSeq) visited;
+ actions.addAll(tmp.getInteractionChildren());
+ }
+ else
+ {
+ @SuppressWarnings("unchecked")
+ SessionNode tmp = (SessionNode) visited;
+ actions.add(tmp);
+ }
+ }
+ return reconstruct(actions);
+ }
+
+ public boolean isEmpty()
+ {
+ return getChildCount() == 0; //this.inters.isEmpty();
+ }
+
+ @Override
+ public String toString()
+ {
+ return getInteractionChildren().stream().map(i -> i.toString())
+ .collect(Collectors.joining("\n"));
+ }
+}
diff --git a/scribble-ast/src/main/java/org/scribble/ast/Module.java b/scribble-ast/src/main/java/org/scribble/ast/Module.java
new file mode 100644
index 000000000..2902e5ae6
--- /dev/null
+++ b/scribble-ast/src/main/java/org/scribble/ast/Module.java
@@ -0,0 +1,264 @@
+/**
+ * Copyright 2008 The Scribble Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.scribble.ast;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Optional;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
+import org.antlr.runtime.Token;
+import org.scribble.ast.global.GProtoDecl;
+import org.scribble.ast.local.LProtoDecl;
+import org.scribble.core.type.kind.Kind;
+import org.scribble.core.type.kind.ProtoKind;
+import org.scribble.core.type.name.DataName;
+import org.scribble.core.type.name.GProtoName;
+import org.scribble.core.type.name.LProtoName;
+import org.scribble.core.type.name.MemberName;
+import org.scribble.core.type.name.ModuleName;
+import org.scribble.core.type.name.ProtoName;
+import org.scribble.core.type.name.SigName;
+import org.scribble.del.DelFactory;
+import org.scribble.util.ScribException;
+import org.scribble.visit.AstVisitor;
+
+public class Module extends ScribNodeBase
+{
+ public static final int MODDECL_CHILD_INDEX = 0;
+
+ // ScribTreeAdaptor#create constructor
+ public Module(Token payload)
+ {
+ super(payload);
+ }
+
+ // Tree#dupNode constructor
+ protected Module(Module node)
+ {
+ super(node);
+ }
+
+ public ModuleDecl getModuleDeclChild()
+ {
+ return (ModuleDecl) getChild(MODDECL_CHILD_INDEX);
+ }
+
+ public List> getImportDeclChildren()
+ {
+ return getMemberChildren(x -> x instanceof ImportDecl,
+ x -> (ImportDecl>) x);
+ }
+
+ public List> getNonProtoDeclChildren()
+ {
+ return getMemberChildren(x -> x instanceof NonProtoDecl,
+ x -> (NonProtoDecl>) x);
+ }
+
+ public List> getProtoDeclChildren()
+ {
+ return getMemberChildren(x -> x instanceof ProtoDecl,
+ x -> (ProtoDecl>) x);
+ }
+
+ // Not requiring T extends ModuleMember, ImportDecl is not a ModuleMember
+ private List getMemberChildren(
+ Predicate instanceOf, Function cast)
+ {
+ List res = new LinkedList<>();
+ boolean b = false;
+ // Start collecting from first instance, and stop on first non-instance or end
+ for (ScribNode c : getChildren())
+ {
+ if (!b && instanceOf.test(c)) b = true;
+ else if (b && !instanceOf.test(c)) break;
+ if (b) res.add(cast.apply(c));
+ }
+ return res;
+ }
+
+ // "add", not "set"
+ public void addScribChildren(ModuleDecl moddecl,
+ List extends ImportDecl>> imports,
+ List extends NonProtoDecl>> data, List extends ProtoDecl>> protos)
+ {
+ // Cf. above getters and Scribble.g children order
+ addChild(moddecl);
+ addChildren(imports);
+ addChildren(data);
+ addChildren(protos);
+ }
+
+ // Cf. CommonTree#dupNode
+ @Override
+ public Module dupNode()
+ {
+ return new Module(this);
+ }
+
+ @Override
+ public void decorateDel(DelFactory df)
+ {
+ df.Module(this);
+ }
+
+ // Set args as children on a dup of this -- children *not* cloned
+ protected Module reconstruct(ModuleDecl moddecl, List> imports,
+ List> data, List> protos)
+ {
+ Module dup = dupNode();
+ dup.addScribChildren(moddecl, imports, data, protos);
+ dup.setDel(del()); // No copy
+ return dup;
+ }
+
+ @Override
+ public Module visitChildren(AstVisitor nv) throws ScribException
+ {
+ ModuleDecl moddecl = (ModuleDecl) visitChild(getModuleDeclChild(), nv);
+ // class equality check probably too restrictive -- FIXME: remove class checks
+ List> imports = ScribNodeBase
+ .visitChildListWithClassEqualityCheck(this, getImportDeclChildren(), nv);
+ List> data = ScribNodeBase
+ .visitChildListWithClassEqualityCheck(this, getNonProtoDeclChildren(), nv);
+ List> protos = ScribNodeBase
+ .visitChildListWithClassEqualityCheck(this, getProtoDeclChildren(), nv);
+ return reconstruct(moddecl, imports, data, protos);
+ }
+
+ public DataDecl getTypeDeclChild(DataName simpname)
+ {
+ return (DataDecl) getNonProtoDeclChild(simpname, NonProtoDecl::isDataDecl);
+ }
+
+ public SigDecl getSigDeclChild(SigName simpname)
+ {
+ return (SigDecl) getNonProtoDeclChild(simpname, NonProtoDecl::isSigDecl);
+ }
+
+ private NonProtoDecl> getNonProtoDeclChild(MemberName> simpname,
+ Predicate> f)
+ {
+ Optional> res = getNonProtoDeclChildren().stream()
+ .filter(x -> f.test(x) && x.getDeclName().equals(simpname))
+ .findFirst(); // No duplication check, rely on WF
+ if (!res.isPresent())
+ {
+ throw new RuntimeException("Data decl not found: " + simpname);
+ }
+ return res.get();
+ }
+
+ public List getGProtoDeclChildren()
+ {
+ return getProtoDeclChildren().stream().filter(x -> x.isGlobal())
+ .map(x -> (GProtoDecl) x).collect(Collectors.toList());
+ // Less efficient, but smaller code
+ }
+
+ public List getLProtoDeclChildren()
+ {
+ return getProtoDeclChildren().stream().filter(x -> x.isLocal())
+ .map(x -> (LProtoDecl) x).collect(Collectors.toList());
+ // Less efficient, but smaller code
+ }
+
+ // CHECKME: allow global and local protocols with same simpname in same module? -- currently, no?
+ public boolean hasGProtocolDecl(GProtoName simpname)
+ {
+ return hasProtocolDeclChild(simpname, ProtoDecl::isGlobal).isPresent();
+ }
+
+ // Pre: hasGProtocolDecl(simpname)
+ public GProtoDecl getGProtocolDeclChild(GProtoName simpname)
+ {
+ Optional> res = hasProtocolDeclChild(simpname,
+ ProtoDecl::isGlobal);
+ if (!res.isPresent())
+ {
+ throw new RuntimeException("Global proto decl not found: " + simpname);
+ }
+ return (GProtoDecl) res.get();
+ }
+
+ public LProtoDecl getLProtocolDeclChild(LProtoName simpname)
+ {
+ Optional> res = hasProtocolDeclChild(simpname,
+ ProtoDecl::isLocal);
+ if (!res.isPresent())
+ {
+ throw new RuntimeException("Local proto decl not found: " + simpname);
+ }
+ return (LProtoDecl) res.get();
+ }
+
+ private Optional> hasProtocolDeclChild(
+ ProtoName> simpname, Predicate> f)
+ {
+ return getProtoDeclChildren().stream()
+ .filter(x -> f.test(x) && x.getHeaderChild().getDeclName().equals(simpname))
+ .findFirst(); // No duplication check, rely on WF
+ }
+
+ public ModuleName getFullModuleName()
+ {
+ return getModuleDeclChild().getFullModuleName();
+ }
+
+ @Override
+ public String toString()
+ {
+ String s = getModuleDeclChild().toString();
+ for (ImportDecl extends Kind> id : getImportDeclChildren())
+ {
+ s += "\n" + id;
+ }
+ for (NonProtoDecl extends Kind> dtd : getNonProtoDeclChildren())
+ {
+ s += "\n" + dtd;
+ }
+ for (ProtoDecl extends ProtoKind> pd : getProtoDeclChildren())
+ {
+ s += "\n" + pd;
+ }
+ return s;
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ /*private static final Predicate IS_GPROTOCOLDECL =
+ x -> (x instanceof ProtocolDecl>) && ((ProtocolDecl>) x).isGlobal();
+
+ private static final Function TO_GPROTOCOLDECL =
+ x -> (GProtocolDecl) x;*/
diff --git a/scribble-ast/src/main/java/org/scribble/ast/ModuleDecl.java b/scribble-ast/src/main/java/org/scribble/ast/ModuleDecl.java
new file mode 100644
index 000000000..98c24e591
--- /dev/null
+++ b/scribble-ast/src/main/java/org/scribble/ast/ModuleDecl.java
@@ -0,0 +1,96 @@
+/**
+ * Copyright 2008 The Scribble Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.scribble.ast;
+
+import org.antlr.runtime.Token;
+import org.scribble.ast.name.qualified.ModuleNameNode;
+import org.scribble.core.type.kind.ModuleKind;
+import org.scribble.core.type.name.ModuleName;
+import org.scribble.del.DelFactory;
+import org.scribble.util.Constants;
+import org.scribble.util.ScribException;
+import org.scribble.visit.AstVisitor;
+
+public class ModuleDecl extends NameDeclNode
+{
+ // ScribTreeAdaptor#create constructor
+ public ModuleDecl(Token t)
+ {
+ super(t);
+ }
+
+ // Tree#dupNode constructor
+ protected ModuleDecl(ModuleDecl node)
+ {
+ super(node);
+ }
+
+ @Override
+ public ModuleNameNode getNameNodeChild()
+ {
+ return (ModuleNameNode) getRawNameNodeChild();
+ }
+
+ // "add", not "set"
+ public void addScribChildren(ModuleNameNode name)
+ {
+ // Cf. above getters and Scribble.g children order
+ addChild(name);
+ }
+
+ // Cf. CommonTree#dupNode
+ @Override
+ public ModuleDecl dupNode()
+ {
+ return new ModuleDecl(this);
+ }
+
+ @Override
+ public void decorateDel(DelFactory df)
+ {
+ df.ModuleDecl(this);
+ }
+
+ protected ModuleDecl reconstruct(ModuleNameNode name)
+ {
+ ModuleDecl dup = dupNode();
+ dup.addScribChildren(name);
+ dup.setDel(del()); // No copy
+ return dup;
+ }
+
+ @Override
+ public ModuleDecl visitChildren(AstVisitor nv) throws ScribException
+ {
+ ModuleNameNode name = (ModuleNameNode) visitChild(getNameNodeChild(), nv);
+ return reconstruct(name);
+ }
+
+ public ModuleName getFullModuleName()
+ {
+ return (ModuleName) getNameNodeChild().toName();
+ }
+
+ @Override
+ public ModuleName getDeclName()
+ {
+ return getNameNodeChild().toName().getSimpleName(); // Uniform with other NameDeclNodes wrt. returning simple name
+ }
+
+ @Override
+ public String toString()
+ {
+ return Constants.MODULE_KW + " " + getFullModuleName() + ";";
+ }
+}
diff --git a/scribble-core/src/main/java/org/scribble/ast/ModuleMember.java b/scribble-ast/src/main/java/org/scribble/ast/ModuleMember.java
similarity index 78%
rename from scribble-core/src/main/java/org/scribble/ast/ModuleMember.java
rename to scribble-ast/src/main/java/org/scribble/ast/ModuleMember.java
index 4be80e0bf..c0ce26cab 100644
--- a/scribble-core/src/main/java/org/scribble/ast/ModuleMember.java
+++ b/scribble-ast/src/main/java/org/scribble/ast/ModuleMember.java
@@ -13,11 +13,12 @@
*/
package org.scribble.ast;
-import org.scribble.type.kind.ModuleMemberKind;
-import org.scribble.type.name.MemberName;
+import org.scribble.core.type.kind.ModuleMemberKind;
+import org.scribble.core.type.name.MemberName;
// Not an abstract class, NonProtocolDecl extends NameDeclNode (whereas ProtocolDecl uses ProtocolHeader for that)
public interface ModuleMember
{
- MemberName extends ModuleMemberKind> getFullMemberName(Module mod); // Should not use ModuleContext -- i.e. works before ModuleContext is built (indeed, context building uses this)
+ MemberName extends ModuleMemberKind> getFullMemberName(Module mod);
+ // Should not use ModuleContext -- i.e. works before ModuleContext is built (indeed, context building uses this)
}
diff --git a/scribble-ast/src/main/java/org/scribble/ast/MsgNode.java b/scribble-ast/src/main/java/org/scribble/ast/MsgNode.java
new file mode 100644
index 000000000..26c4eaf5f
--- /dev/null
+++ b/scribble-ast/src/main/java/org/scribble/ast/MsgNode.java
@@ -0,0 +1,24 @@
+/**
+ * Copyright 2008 The Scribble Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.scribble.ast;
+
+import org.scribble.core.type.session.Msg;
+
+// A sig kind node: MessageSignatureNode, MessageSignatureNameNode or NonRoleParamNode
+public interface MsgNode extends NonRoleArgNode
+{
+ Msg toMsg();
+
+ //Arg extends SigKind> toArg(); // Not possible due to "diamond" with PayloadElemNameNode at AmbigNameNode
+}
diff --git a/scribble-ast/src/main/java/org/scribble/ast/MsgTransfer.java b/scribble-ast/src/main/java/org/scribble/ast/MsgTransfer.java
new file mode 100644
index 000000000..b73eb146d
--- /dev/null
+++ b/scribble-ast/src/main/java/org/scribble/ast/MsgTransfer.java
@@ -0,0 +1,35 @@
+/**
+ * Copyright 2008 The Scribble Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.scribble.ast;
+
+import org.antlr.runtime.Token;
+import org.scribble.core.type.kind.ProtoKind;
+
+public abstract class MsgTransfer
+ extends DirectedInteraction
+{
+ // ScribTreeAdaptor#create constructor
+ public MsgTransfer(Token t)
+ {
+ super(t);
+ }
+
+ // Tree#dupNode constructor
+ public MsgTransfer(MsgTransfer node)
+ {
+ super(node);
+ }
+}
+
+
diff --git a/scribble-ast/src/main/java/org/scribble/ast/NameDeclNode.java b/scribble-ast/src/main/java/org/scribble/ast/NameDeclNode.java
new file mode 100644
index 000000000..5492874bb
--- /dev/null
+++ b/scribble-ast/src/main/java/org/scribble/ast/NameDeclNode.java
@@ -0,0 +1,57 @@
+/**
+ * Copyright 2008 The Scribble Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.scribble.ast;
+
+import org.antlr.runtime.Token;
+import org.scribble.ast.name.NameNode;
+import org.scribble.core.type.kind.Kind;
+import org.scribble.core.type.name.Name;
+
+public abstract class NameDeclNode extends ScribNodeBase
+{
+ public static final int NAMENODE_CHILD_INDEX = 0;
+
+ // ScribTreeAdaptor#create constructor
+ public NameDeclNode(Token t)
+ {
+ super(t);
+ }
+
+ // Tree#dupNode constructor
+ public NameDeclNode(NameDeclNode node)
+ {
+ super(node);
+ }
+
+ // CHECKME: always AmbigNameNode?
+ protected final NameNode> getRawNameNodeChild()
+ {
+ if (getChildCount() < 1) // E.g., ProtocolHeader three children
+ {
+ throw new RuntimeException("Shouldn't get in here: " + getClass());
+ }
+ NameNode> name = (NameNode>) getChild(NAMENODE_CHILD_INDEX);
+ return name;
+ }
+
+ // Concrete subclasses should use getRawNameNodeChild() and cast
+ // (Avoids needing to explicitly record the kind, cf. NonRoleParamDecl)
+ // (Gets overridden anyway for return type)
+ public abstract NameNode getNameNodeChild();
+
+ // Return: *simple* name (cf. ModuleDecl)
+ // Concrete subclasses should use getNameNode, toName (simple name) and cast
+ // (Gets overridden anyway for return type)
+ public abstract Name getDeclName();
+}
diff --git a/scribble-ast/src/main/java/org/scribble/ast/NonProtoDecl.java b/scribble-ast/src/main/java/org/scribble/ast/NonProtoDecl.java
new file mode 100644
index 000000000..2a87b1de6
--- /dev/null
+++ b/scribble-ast/src/main/java/org/scribble/ast/NonProtoDecl.java
@@ -0,0 +1,124 @@
+/**
+ * Copyright 2008 The Scribble Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.scribble.ast;
+
+import org.antlr.runtime.Token;
+import org.scribble.ast.name.NameNode;
+import org.scribble.ast.name.simple.ExtIdNode;
+import org.scribble.ast.name.simple.IdNode;
+import org.scribble.core.type.kind.NonProtoKind;
+import org.scribble.util.ScribException;
+import org.scribble.visit.AstVisitor;
+
+// Rename to something better
+public abstract class NonProtoDecl
+ extends NameDeclNode implements ModuleMember
+{
+ // NameDeclNode.NAMENODE_CHILD_INDEX = 0;
+ public static final int SCHEMA_NODE_CHILD_INDEX = 1;
+ public static final int EXTNAME_NODE_CHILD_INDEX = 2;
+ public static final int EXTSOURCE_NODE_CHILD_INDEX = 3;
+
+ // ScribTreeAdaptor#create constructor
+ public NonProtoDecl(Token payload)
+ {
+ super(payload);
+ }
+
+ // Tree#dupNode constructor
+ protected NonProtoDecl(NonProtoDecl node)
+ {
+ super(node);
+ }
+
+ // Redundant override, just for documentation
+ @Override
+ public abstract NameNode getNameNodeChild();
+
+ public IdNode getSchemaChild()
+ {
+ return (IdNode) getChild(SCHEMA_NODE_CHILD_INDEX);
+ }
+
+ public ExtIdNode getExtNameChild()
+ {
+ return (ExtIdNode) getChild(EXTNAME_NODE_CHILD_INDEX);
+ }
+
+ public ExtIdNode getExtSourceChild()
+ {
+ return (ExtIdNode) getChild(EXTSOURCE_NODE_CHILD_INDEX);
+ }
+
+ // "add", not "set"
+ public void addScribChildren(NameNode name, IdNode schema,
+ ExtIdNode extName, ExtIdNode extSource)
+ {
+ // Cf. above getters and Scribble.g children order
+ addChild(name);
+ addChild(schema);
+ addChild(extName);
+ addChild(extSource);
+ }
+
+ // CHECKME: maybe move to ModuleMember
+ public boolean isDataDecl()
+ {
+ return false;
+ }
+
+ public boolean isSigDecl()
+ {
+ return false;
+ }
+
+ @Override
+ public abstract NonProtoDecl dupNode();
+
+ public NonProtoDecl reconstruct(NameNode name, IdNode schema,
+ ExtIdNode extName, ExtIdNode extSource)
+ {
+ NonProtoDecl dup = dupNode();
+ dup.addScribChildren(name, schema, extName, extSource);
+ dup.setDel(del()); // No copy
+ return dup;
+ }
+
+ @Override
+ public NonProtoDecl visitChildren(AstVisitor nv)
+ throws ScribException
+ {
+ NameNode name = (NameNode) visitChildWithClassEqualityCheck(this,
+ getNameNodeChild(), nv);
+ IdNode schema = getSchemaChild();
+ ExtIdNode extName = getExtNameChild();
+ ExtIdNode extSource = getExtSourceChild();
+ return reconstruct(name, schema, extName, extSource);
+ }
+
+ public String getSchema()
+ {
+ return getSchemaChild().getText();
+ }
+
+ public String getExtName()
+ {
+ return getExtNameChild().getText();
+ }
+
+ public String getExtSource()
+ {
+ return getExtSourceChild().getText();
+ }
+}
diff --git a/scribble-ast/src/main/java/org/scribble/ast/NonRoleArg.java b/scribble-ast/src/main/java/org/scribble/ast/NonRoleArg.java
new file mode 100644
index 000000000..9358573f1
--- /dev/null
+++ b/scribble-ast/src/main/java/org/scribble/ast/NonRoleArg.java
@@ -0,0 +1,52 @@
+/**
+ * Copyright 2008 The Scribble Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.scribble.ast;
+
+import org.antlr.runtime.Token;
+import org.scribble.del.DelFactory;
+
+public class NonRoleArg extends DoArg
+{
+ public static final int ARG_NODE_CHILD_INDEX = 0;
+
+ // ScribTreeAdaptor#create constructor
+ public NonRoleArg(Token t)
+ {
+ super(t);
+ }
+
+ // Tree#dupNode constructor
+ public NonRoleArg(NonRoleArg node)
+ {
+ super(node);
+ }
+
+ @Override
+ public NonRoleArgNode getArgNodeChild()
+ {
+ return (NonRoleArgNode) getChild(ARG_NODE_CHILD_INDEX);
+ }
+
+ @Override
+ public NonRoleArg dupNode()
+ {
+ return new NonRoleArg(this);
+ }
+
+ @Override
+ public void decorateDel(DelFactory df)
+ {
+ df.NonRoleArg(this);
+ }
+}
diff --git a/scribble-ast/src/main/java/org/scribble/ast/NonRoleArgList.java b/scribble-ast/src/main/java/org/scribble/ast/NonRoleArgList.java
new file mode 100644
index 000000000..bc9b951d7
--- /dev/null
+++ b/scribble-ast/src/main/java/org/scribble/ast/NonRoleArgList.java
@@ -0,0 +1,115 @@
+/**
+ * Copyright 2008 The Scribble Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.scribble.ast;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.antlr.runtime.Token;
+import org.scribble.core.type.kind.NonRoleArgKind;
+import org.scribble.core.type.kind.NonRoleParamKind;
+import org.scribble.core.type.name.DataName;
+import org.scribble.core.type.name.SigName;
+import org.scribble.core.type.session.Arg;
+import org.scribble.core.type.session.SigLit;
+import org.scribble.del.DelFactory;
+
+// Cf. NonRoleParamDeclList
+public class NonRoleArgList extends DoArgList
+{
+ // ScribTreeAdaptor#create constructor
+ public NonRoleArgList(Token t)
+ {
+ super(t);
+ }
+
+ // Tree#dupNode constructor
+ public NonRoleArgList(NonRoleArgList node)
+ {
+ super(node);
+ }
+
+ @Override
+ public List getArgChildren()
+ {
+ return getRawArgChildren().stream().map(x -> (NonRoleArg) x)
+ .collect(Collectors.toList());
+ }
+
+ public List getArgNodes()
+ {
+ return getArgChildren().stream().map(x -> x.getArgNodeChild())
+ .collect(Collectors.toList());
+ }
+
+ public boolean isEmpty()
+ {
+ return getArgChildren().isEmpty();
+ }
+
+ // Can return a mix of arg kinds
+ public List> getArguments()
+ {
+ return getArgChildren().stream()
+ .map(x -> (Arg>) x.getArgNodeChild().toArg())
+ .collect(Collectors.toList());
+ }
+
+ // Cast all, assuming no Ambig
+ public List> getParamKindArgs()
+ {
+ List> cast = new LinkedList<>();
+ for (Arg extends NonRoleArgKind> a : getArguments())
+ {
+ if (a instanceof SigLit)
+ {
+ cast.add((SigLit) a);
+ }
+ else if (a instanceof DataName)
+ {
+ cast.add((DataName) a);
+ }
+ else if (a instanceof SigName)
+ {
+ cast.add((SigName) a);
+ }
+ else
+ {
+ throw new RuntimeException("TODO: " + a);
+ }
+ }
+ return cast;
+ }
+
+ @Override
+ public NonRoleArgList dupNode()
+ {
+ return new NonRoleArgList(this);
+ }
+
+ @Override
+ public void decorateDel(DelFactory df)
+ {
+ df.NonRoleArgList(this);
+ }
+
+ @Override
+ public String toString()
+ {
+ return getArgChildren().isEmpty()
+ ? ""
+ : "<" + super.toString() + ">";
+ }
+}
diff --git a/scribble-core/src/main/java/org/scribble/ast/NonRoleArgNode.java b/scribble-ast/src/main/java/org/scribble/ast/NonRoleArgNode.java
similarity index 82%
rename from scribble-core/src/main/java/org/scribble/ast/NonRoleArgNode.java
rename to scribble-ast/src/main/java/org/scribble/ast/NonRoleArgNode.java
index c4d9c43fe..8a1f0ff4e 100644
--- a/scribble-core/src/main/java/org/scribble/ast/NonRoleArgNode.java
+++ b/scribble-ast/src/main/java/org/scribble/ast/NonRoleArgNode.java
@@ -13,35 +13,40 @@
*/
package org.scribble.ast;
-import org.scribble.type.Arg;
-import org.scribble.type.kind.NonRoleArgKind;
+import org.scribble.core.type.kind.NonRoleArgKind;
+import org.scribble.core.type.session.Arg;
// sig or payloadtype kinds that can be used as do arg vals, cf. RoleNode
// "Value nodes" (sigs or names) that can be used as non-role subprotocol arguments (doesn't include role instantation arguments)
// N.B. not the actual argument node itself (that is NonRoleArg, element of NonRoleArgList, which wraps these nodes)
public interface NonRoleArgNode extends DoArgNode
{
+ Arg extends NonRoleArgKind> toArg();
+
// Not kinded: point of this interface is don't know which kind the node is -- so use the "is" methods -- cf. AmbigNameNode inherits both sig and data kind
// And not all values are names, e.g. message sigs
- default boolean isMessageSigNode()
+ default boolean isSigLitNode()
{
return false;
}
- default boolean isMessageSigNameNode()
+ default boolean isSigNameNode()
{
return false;
}
- default boolean isDataTypeNameNode()
+ default boolean isDataNameNode()
{
return false;
}
- default boolean isParamNode()
+ default boolean isSigParamNode()
+ {
+ return false;
+ }
+
+ default boolean isDataParamNode()
{
return false;
}
-
- Arg extends NonRoleArgKind> toArg();
}
diff --git a/scribble-ast/src/main/java/org/scribble/ast/NonRoleParamDecl.java b/scribble-ast/src/main/java/org/scribble/ast/NonRoleParamDecl.java
new file mode 100644
index 000000000..680964d38
--- /dev/null
+++ b/scribble-ast/src/main/java/org/scribble/ast/NonRoleParamDecl.java
@@ -0,0 +1,42 @@
+/**
+ * Copyright 2008 The Scribble Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.scribble.ast;
+
+import org.antlr.runtime.Token;
+import org.scribble.core.type.kind.NonRoleParamKind;
+import org.scribble.core.type.name.MemberName;
+
+// CHECKME: drop generic parameter and kind?
+public abstract class NonRoleParamDecl
+ extends ParamDecl
+{
+ public final K kind; // CHECKME: factor up to super?
+
+ // ScribTreeAdaptor#create constructor
+ public NonRoleParamDecl(Token t, K kind)
+ {
+ super(t);
+ this.kind = kind;
+ }
+
+ // Tree#dupNode constructor
+ public NonRoleParamDecl(NonRoleParamDecl node)
+ {
+ super(node);
+ this.kind = node.kind;
+ }
+
+ @Override
+ public abstract MemberName getDeclName(); // DataType/MessageSigName are MemberNames
+}
diff --git a/scribble-ast/src/main/java/org/scribble/ast/NonRoleParamDeclList.java b/scribble-ast/src/main/java/org/scribble/ast/NonRoleParamDeclList.java
new file mode 100644
index 000000000..deecc8b45
--- /dev/null
+++ b/scribble-ast/src/main/java/org/scribble/ast/NonRoleParamDeclList.java
@@ -0,0 +1,94 @@
+/**
+ * Copyright 2008 The Scribble Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.scribble.ast;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.antlr.runtime.Token;
+import org.scribble.core.type.kind.NonRoleParamKind;
+import org.scribble.core.type.name.MemberName;
+import org.scribble.del.DelFactory;
+
+// Can contain "mixed" type/sig kinds
+// Typing a bit awkward that this list has to use NonRoleParamKind as the "concrete" kind, while the NonRoleParamDecl elements use the actual concrete kind
+// But OK because the NonRoleParamDecl nodes are immutable (the generic kind value is never rewritten after instantiation, only read)
+public class NonRoleParamDeclList extends ParamDeclList
+{
+ // ScribTreeAdaptor#create constructor
+ public NonRoleParamDeclList(Token t)
+ {
+ super(t);
+ }
+
+ // Tree#dupNode constructor
+ public NonRoleParamDeclList(NonRoleParamDeclList node)
+ {
+ super(node);
+ }
+
+ @Override
+ public List> getDeclChildren()
+ {
+ @SuppressWarnings("unchecked")
+ List> cast =
+ getChildren().stream()
+ .map(x -> (NonRoleParamDecl) x) // Cast specifically to NonRoleParamKind (not "?") for hetero list
+ .collect(Collectors.toList());
+ return cast;
+ }
+
+ /*// "add", not "set"
+ public void addScribChildren(List extends ParamDecl extends NonRoleParamKind>> ds)
+ {
+ // Cf. above getters and Scribble.g children order
+ super.addChildren(ds);
+ }*/
+
+ @Override
+ public NonRoleParamDeclList dupNode()
+ {
+ return new NonRoleParamDeclList(this);
+ }
+
+ @Override
+ public void decorateDel(DelFactory df)
+ {
+ df.NonRoleParamDeclList(this);
+ }
+
+ @Override
+ public NonRoleParamDeclList reconstruct(
+ List extends ParamDecl> ds)
+ {
+ NonRoleParamDeclList dup = dupNode();
+ dup.addScribChildren(ds);
+ dup.setDel(del()); // No copy
+ return dup;
+ }
+
+ public List> getParams()
+ {
+ return getDeclChildren().stream().map(decl -> decl.getDeclName())
+ .collect(Collectors.toList());
+ }
+
+ @Override
+ public String toString()
+ {
+ return (isEmpty())
+ ? ""
+ : "<" + super.toString() + ">";
+ }
+}
diff --git a/scribble-ast/src/main/java/org/scribble/ast/ParamDecl.java b/scribble-ast/src/main/java/org/scribble/ast/ParamDecl.java
new file mode 100644
index 000000000..026e306a6
--- /dev/null
+++ b/scribble-ast/src/main/java/org/scribble/ast/ParamDecl.java
@@ -0,0 +1,75 @@
+/**
+ * Copyright 2008 The Scribble Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.scribble.ast;
+
+import org.antlr.runtime.Token;
+import org.scribble.ast.name.NameNode;
+import org.scribble.core.type.kind.ParamKind;
+import org.scribble.util.ScribException;
+import org.scribble.visit.AstVisitor;
+
+// Names that are declared in a protocol header (roles and parameters -- not the protocol name though)
+// RoleKind or (NonRole)ParamKind
+public abstract class ParamDecl
+ extends NameDeclNode
+{
+ // ScribTreeAdaptor#create constructor
+ public ParamDecl(Token t)
+ {
+ super(t);
+ }
+
+ // Tree#dupNode constructor
+ public ParamDecl(ParamDecl node)
+ {
+ super(node);
+ }
+
+ @Override
+ public abstract NameNode getNameNodeChild(); // Always a "simple" name (e.g., like Role), but Type/Sig names are not SimpleNames
+
+ public abstract String getKeyword();
+
+ // "add", not "set"
+ public void addScribChildren(NameNode name)
+ {
+ // Cf. above getters and Scribble.g children order
+ addChild(name);
+ }
+
+ public abstract ParamDecl dupNode();
+
+ public ParamDecl reconstruct(NameNode name) // Always a "simple" name (e.g., like Role), but Type/Sig names are not SimpleNames
+ {
+ ParamDecl dup = dupNode();
+ dup.addScribChildren(name);
+ dup.setDel(del()); // No copy
+ return dup;
+ }
+
+ @Override
+ public ParamDecl visitChildren(AstVisitor nv)
+ throws ScribException
+ {
+ NameNode name =
+ visitChildWithClassEqualityCheck(this, getNameNodeChild(), nv);
+ return reconstruct(name);
+ }
+
+ @Override
+ public String toString()
+ {
+ return getKeyword() + " " + getDeclName().toString();
+ }
+}
diff --git a/scribble-ast/src/main/java/org/scribble/ast/ParamDeclList.java b/scribble-ast/src/main/java/org/scribble/ast/ParamDeclList.java
new file mode 100644
index 000000000..0637fa0d4
--- /dev/null
+++ b/scribble-ast/src/main/java/org/scribble/ast/ParamDeclList.java
@@ -0,0 +1,87 @@
+/**
+ * Copyright 2008 The Scribble Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.scribble.ast;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.antlr.runtime.Token;
+import org.scribble.core.type.kind.ParamKind;
+import org.scribble.util.ScribException;
+import org.scribble.visit.AstVisitor;
+
+
+// RoleKind or (NonRole)ParamKind
+public abstract class ParamDeclList extends ScribNodeBase
+{
+ // ScribTreeAdaptor#create constructor
+ public ParamDeclList(Token t)
+ {
+ super(t);
+ }
+
+ // Tree#dupNode constructor
+ public ParamDeclList(ParamDeclList node)
+ {
+ super(node);
+ }
+
+ public abstract List extends ParamDecl> getDeclChildren();
+
+ // "add", not "set"
+ public void addScribChildren(List extends ParamDecl extends K>> ds)
+ {
+ // Cf. above getters and Scribble.g children order
+ super.addChildren(ds);
+ }
+
+ @Override
+ public abstract ParamDeclList dupNode();
+
+ public ParamDeclList reconstruct(
+ List extends ParamDecl> ds)
+ {
+ ParamDeclList dup = dupNode();
+ dup.addScribChildren(ds);
+ dup.setDel(del()); // No copy
+ return dup;
+ }
+
+ @Override
+ public ParamDeclList extends K> visitChildren(AstVisitor v)
+ throws ScribException
+ {
+ List extends ParamDecl> ps =
+ visitChildListWithClassEqualityCheck(this, getDeclChildren(), v);
+ return reconstruct(ps);
+ }
+
+ public final int length()
+ {
+ return getDeclChildren().size();
+ }
+
+ public final boolean isEmpty()
+ {
+ return length() == 0;
+ }
+
+ // Without enclosing braces -- added by subclasses
+ @Override
+ public String toString()
+ {
+ return getDeclChildren().stream().map(x -> x.toString())
+ .collect(Collectors.joining(", "));
+ }
+}
diff --git a/scribble-ast/src/main/java/org/scribble/ast/PayElem.java b/scribble-ast/src/main/java/org/scribble/ast/PayElem.java
new file mode 100644
index 000000000..6ee4c8711
--- /dev/null
+++ b/scribble-ast/src/main/java/org/scribble/ast/PayElem.java
@@ -0,0 +1,33 @@
+/**
+ * Copyright 2008 The Scribble Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.scribble.ast;
+
+import org.scribble.core.type.kind.PayElemKind;
+import org.scribble.core.type.name.PayElemType;
+
+// Not in grammar file -- but cf. DoArg (and PayloadElemList cf. DoArgList) -- i.e. need a wrapper for mixed and initially ambiguous name kinds
+public interface PayElem extends ScribNode
+{
+ PayElemType extends PayElemKind> toPayloadType(); // Mainly a wrapper method for the wrapped NameNode
+
+ default boolean isGlobalDelegationElem()
+ {
+ return false;
+ }
+
+ default boolean isLocalDelegationElem()
+ {
+ return false;
+ }
+}
diff --git a/scribble-ast/src/main/java/org/scribble/ast/PayElemList.java b/scribble-ast/src/main/java/org/scribble/ast/PayElemList.java
new file mode 100644
index 000000000..83320b044
--- /dev/null
+++ b/scribble-ast/src/main/java/org/scribble/ast/PayElemList.java
@@ -0,0 +1,100 @@
+/**
+ * Copyright 2008 The Scribble Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.scribble.ast;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.antlr.runtime.Token;
+import org.scribble.core.type.name.PayElemType;
+import org.scribble.core.type.session.Payload;
+import org.scribble.del.DelFactory;
+import org.scribble.util.ScribException;
+import org.scribble.visit.AstVisitor;
+
+// Cf. DoArgList, but here we don't need as much abstraction (cf. RoleArgList, NonRoleArgList)
+public class PayElemList extends ScribNodeBase
+{
+ // ScribTreeAdaptor#create constructor
+ public PayElemList(Token t)
+ {
+ super(t);
+ }
+
+ // Tree#dupNode constructor
+ public PayElemList(PayElemList node)
+ {
+ super(node);
+ }
+
+ List> getElementChildren()
+ {
+ return getChildren().stream().map(x -> (PayElem>) x)
+ .collect(Collectors.toList());
+ }
+
+ // "add", not "set"
+ public void addScribChildren(List> elems)
+ {
+ // Cf. above getters and Scribble.g children order
+ super.addChildren(elems);
+ }
+
+ @Override
+ public PayElemList dupNode()
+ {
+ return new PayElemList(this);
+ }
+
+ @Override
+ public void decorateDel(DelFactory df)
+ {
+ df.PayElemList(this);
+ }
+
+ protected PayElemList reconstruct(List> elems)
+ {
+ PayElemList dup = dupNode();
+ dup.addScribChildren(elems);
+ dup.setDel(del()); // No copy
+ return dup;
+ }
+
+ @Override
+ public PayElemList visitChildren(AstVisitor nv) throws ScribException
+ {
+ List> elems =
+ visitChildListWithClassEqualityCheck(this, getElementChildren(), nv);
+ return reconstruct(elems);
+ }
+
+ public Payload toPayload()
+ {
+ List> elems = getElementChildren().stream()
+ .map(x -> x.toPayloadType()).collect(Collectors.toList());
+ return new Payload(elems);
+ }
+
+ public boolean isEmpty()
+ {
+ return getChildCount() == 0;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "(" + getElementChildren().stream().map(x -> x.toString())
+ .collect(Collectors.joining(", ")) + ")";
+ }
+}
diff --git a/scribble-ast/src/main/java/org/scribble/ast/ProtoBlock.java b/scribble-ast/src/main/java/org/scribble/ast/ProtoBlock.java
new file mode 100644
index 000000000..292392c0d
--- /dev/null
+++ b/scribble-ast/src/main/java/org/scribble/ast/ProtoBlock.java
@@ -0,0 +1,76 @@
+/**
+ * Copyright 2008 The Scribble Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.scribble.ast;
+
+import org.antlr.runtime.Token;
+import org.scribble.core.type.kind.ProtoKind;
+import org.scribble.util.ScribException;
+import org.scribble.visit.AstVisitor;
+
+public abstract class ProtoBlock
+ extends ScribNodeBase
+{
+ public static final int SEQ_CHILD_INDEX = 0;
+
+ // ScribTreeAdaptor#create constructor
+ public ProtoBlock(Token t)
+ {
+ super(t);
+ }
+
+ // Tree#dupNode constructor
+ protected ProtoBlock(ProtoBlock node)
+ {
+ super(node);
+ }
+
+ public abstract InteractionSeq getInteractSeqChild();
+
+ public boolean isEmpty()
+ {
+ return getInteractSeqChild().isEmpty();
+ }
+
+ // "add", not "set"
+ public void addScribChildren(InteractionSeq seq)
+ {
+ // Cf. above getters and Scribble.g children order
+ addChild(seq);
+ }
+
+ @Override
+ public abstract ProtoBlock dupNode();
+
+ public ProtoBlock reconstruct(InteractionSeq seq)
+ {
+ ProtoBlock dup = dupNode();
+ dup.addScribChildren(seq);
+ dup.setDel(del()); // No copy
+ return dup;
+ }
+
+ @Override
+ public ProtoBlock visitChildren(AstVisitor nv) throws ScribException
+ {
+ InteractionSeq seq =
+ visitChildWithClassEqualityCheck(this, getInteractSeqChild(), nv);
+ return reconstruct(seq);
+ }
+
+ @Override
+ public String toString()
+ {
+ return "{\n" + getInteractSeqChild() + "\n}"; // Empty block will contain an blank line
+ }
+}
diff --git a/scribble-ast/src/main/java/org/scribble/ast/ProtoDecl.java b/scribble-ast/src/main/java/org/scribble/ast/ProtoDecl.java
new file mode 100644
index 000000000..a5c0dbc6a
--- /dev/null
+++ b/scribble-ast/src/main/java/org/scribble/ast/ProtoDecl.java
@@ -0,0 +1,108 @@
+/**
+ * Copyright 2008 The Scribble Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.scribble.ast;
+
+import java.util.List;
+
+import org.antlr.runtime.Token;
+import org.scribble.core.type.kind.ProtoKind;
+import org.scribble.core.type.name.Role;
+import org.scribble.util.ScribException;
+import org.scribble.visit.AstVisitor;
+
+// CHECKME: visitChildren for modifiers
+public abstract class ProtoDecl extends ScribNodeBase
+ implements ModuleMember, ProtoKindNode
+{
+ public static final int MODLIST_CHILD = 0;
+ public static final int HEADER_CHILD = 1;
+ public static final int DEF_CHILD = 2;
+
+ // ScribTreeAdaptor#create constructor
+ protected ProtoDecl(Token t)
+ {
+ super(t);
+ }
+
+ // Tree#dupNode constructor
+ protected ProtoDecl(ProtoDecl node)
+ {
+ super(node);
+ }
+
+ public ProtoModList getModifierListChild()
+ {
+ return (ProtoModList) getChild(MODLIST_CHILD);
+ }
+
+ // Implement in subclasses to avoid generic cast
+ public abstract ProtoHeader getHeaderChild();
+ public abstract ProtoDef getDefChild();
+
+ // "add", not "set"
+ public void addScribChildren(ProtoModList mods, ProtoHeader header,
+ ProtoDef def)
+ {
+ // Cf. above getters and Scribble.g children order
+ addChild(mods);
+ addChild(header);
+ addChild(def);
+ }
+
+ public boolean isAux()
+ {
+ return getModifierListChild().hasAux();
+ }
+
+ public boolean isExplicit()
+ {
+ return getModifierListChild().hasExplicit();
+ }
+
+ public abstract ProtoDecl dupNode();
+
+ public ProtoDecl reconstruct(ProtoModList mods, ProtoHeader header,
+ ProtoDef def)
+ {
+ ProtoDecl dup = dupNode();
+ dup.addScribChildren(mods, header, def);
+ dup.setDel(del()); // No copy
+ return dup;
+ }
+
+ @Override
+ public ProtoDecl visitChildren(AstVisitor v) throws ScribException
+ {
+ ProtoModList mods = visitChildWithClassEqualityCheck(this,
+ getModifierListChild(), v);
+ ProtoHeader header =
+ visitChildWithClassEqualityCheck(this, getHeaderChild(), v);
+ ProtoDef def = visitChildWithClassEqualityCheck(this, getDefChild(), v);
+ return reconstruct(mods, header, def);
+ }
+
+ public List getRoles()
+ {
+ // WF disallows unused role declarations
+ return getHeaderChild().getRoleDeclListChild().getRoles();
+ }
+
+ @Override
+ public String toString()
+ {
+ ProtoModList mods = getModifierListChild();
+ return (mods.isEmpty() ? "" : mods + " ") + getHeaderChild() + " "
+ + getDefChild();
+ }
+}
diff --git a/scribble-ast/src/main/java/org/scribble/ast/ProtoDef.java b/scribble-ast/src/main/java/org/scribble/ast/ProtoDef.java
new file mode 100644
index 000000000..85d75c949
--- /dev/null
+++ b/scribble-ast/src/main/java/org/scribble/ast/ProtoDef.java
@@ -0,0 +1,69 @@
+/**
+ * Copyright 2008 The Scribble Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.scribble.ast;
+
+import org.antlr.runtime.Token;
+import org.scribble.core.type.kind.ProtoKind;
+import org.scribble.util.ScribException;
+import org.scribble.visit.AstVisitor;
+
+public abstract class ProtoDef extends ScribNodeBase
+ implements ProtoKindNode
+{
+ public static final int BLOCK_CHILD_INDEX = 0;
+
+ // ScribTreeAdaptor#create constructor
+ public ProtoDef(Token t)
+ {
+ super(t);
+ }
+
+ // Tree#dupNode constructor
+ protected ProtoDef(ProtoDef node)
+ {
+ super(node);
+ }
+ public abstract ProtoBlock getBlockChild();
+
+ // "add", not "set"
+ public void addScribChildren(ProtoBlock block)
+ {
+ // Cf. above getters and Scribble.g children order
+ addChild(block);
+ }
+
+ public abstract ProtoDef dupNode();
+
+ public ProtoDef reconstruct(ProtoBlock block)
+ {
+ ProtoDef dup = dupNode();
+ dup.addScribChildren(block);
+ dup.setDel(del()); // No copy
+ return dup;
+ }
+
+ @Override
+ public ProtoDef visitChildren(AstVisitor nv) throws ScribException
+ {
+ ProtoBlock block =
+ visitChildWithClassEqualityCheck(this, getBlockChild(), nv);
+ return reconstruct(block);
+ }
+
+ @Override
+ public String toString()
+ {
+ return getBlockChild().toString();
+ }
+}
diff --git a/scribble-ast/src/main/java/org/scribble/ast/ProtoHeader.java b/scribble-ast/src/main/java/org/scribble/ast/ProtoHeader.java
new file mode 100644
index 000000000..980f1a32c
--- /dev/null
+++ b/scribble-ast/src/main/java/org/scribble/ast/ProtoHeader.java
@@ -0,0 +1,111 @@
+/**
+ * Copyright 2008 The Scribble Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.scribble.ast;
+
+import org.antlr.runtime.Token;
+import org.scribble.ast.name.qualified.ProtoNameNode;
+import org.scribble.core.type.kind.ProtoKind;
+import org.scribble.core.type.name.ProtoName;
+import org.scribble.util.Constants;
+import org.scribble.util.ScribException;
+import org.scribble.visit.AstVisitor;
+
+// TODO: parameterize on global/local name node and role decl list (i.e. self roles)
+public abstract class ProtoHeader
+ extends NameDeclNode implements ProtoKindNode