You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ah...@apache.org on 2019/10/03 21:12:14 UTC

[royale-compiler] 02/10: webservice handling

This is an automated email from the ASF dual-hosted git repository.

aharui pushed a commit to branch webservice
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git

commit 9dc0ad422ebb7b9846f47cb49328a246114901b0
Author: Alex Harui <ah...@apache.org>
AuthorDate: Thu Sep 26 15:11:34 2019 -0700

    webservice handling
---
 .../royale/compiler/codegen/mxml/IMXMLEmitter.java |   7 ++
 .../internal/codegen/mxml/MXMLBlockWalker.java     |  19 ++++
 .../internal/codegen/mxml/MXMLEmitter.java         |  14 +++
 .../codegen/mxml/royale/MXMLRoyaleEmitter.java     | 117 +++++++++++++++++++++
 .../internal/visitor/mxml/MXMLNodeSwitch.java      |  10 +-
 .../compiler/visitor/mxml/IMXMLBlockVisitor.java   |   6 ++
 6 files changed, 171 insertions(+), 2 deletions(-)

diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/codegen/mxml/IMXMLEmitter.java b/compiler-jx/src/main/java/org/apache/royale/compiler/codegen/mxml/IMXMLEmitter.java
index 956384c..e20f8c9 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/codegen/mxml/IMXMLEmitter.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/codegen/mxml/IMXMLEmitter.java
@@ -47,6 +47,8 @@ import org.apache.royale.compiler.tree.mxml.IMXMLStringNode;
 import org.apache.royale.compiler.tree.mxml.IMXMLStyleSpecifierNode;
 import org.apache.royale.compiler.tree.mxml.IMXMLUintNode;
 import org.apache.royale.compiler.tree.mxml.IMXMLVectorNode;
+import org.apache.royale.compiler.tree.mxml.IMXMLWebServiceNode;
+import org.apache.royale.compiler.tree.mxml.IMXMLWebServiceOperationNode;
 import org.apache.royale.compiler.visitor.IASNodeStrategy;
 import org.apache.royale.compiler.visitor.IBlockWalker;
 
@@ -145,4 +147,9 @@ public interface IMXMLEmitter extends IEmitter
 
 	void emitRemoteObject(IMXMLRemoteObjectNode node);
 
+    //--------------------------------------------------------------------------
+
+    void emitWebServiceMethod(IMXMLWebServiceOperationNode node);
+
+	void emitWebService(IMXMLWebServiceNode node);
 }
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/MXMLBlockWalker.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/MXMLBlockWalker.java
index 8a1dbab..5faa900 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/MXMLBlockWalker.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/MXMLBlockWalker.java
@@ -58,6 +58,8 @@ import org.apache.royale.compiler.tree.mxml.IMXMLStyleNode;
 import org.apache.royale.compiler.tree.mxml.IMXMLStyleSpecifierNode;
 import org.apache.royale.compiler.tree.mxml.IMXMLUintNode;
 import org.apache.royale.compiler.tree.mxml.IMXMLVectorNode;
+import org.apache.royale.compiler.tree.mxml.IMXMLWebServiceNode;
+import org.apache.royale.compiler.tree.mxml.IMXMLWebServiceOperationNode;
 import org.apache.royale.compiler.units.ICompilationUnit;
 import org.apache.royale.compiler.visitor.IASNodeStrategy;
 import org.apache.royale.compiler.visitor.IBlockWalker;
@@ -460,6 +462,23 @@ public class MXMLBlockWalker implements IMXMLBlockVisitor, IMXMLBlockWalker
 	}
     
     //--------------------------------------------------------------------------
+    
+    @Override
+    public void visitWebServiceMethod(IMXMLWebServiceOperationNode node)
+    {
+        debug("visitWebServiceMethod()");
+        
+        mxmlEmitter.emitWebServiceMethod(node);
+    }
+    
+	@Override
+	public void visitWebService(IMXMLWebServiceNode node) {
+        debug("visitWebService()");
+        
+        mxmlEmitter.emitWebService(node);		
+	}
+    
+    //--------------------------------------------------------------------------
 
     protected void debug(String message)
     {
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/MXMLEmitter.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/MXMLEmitter.java
index 2027827..1296684 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/MXMLEmitter.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/MXMLEmitter.java
@@ -55,6 +55,8 @@ import org.apache.royale.compiler.tree.mxml.IMXMLStringNode;
 import org.apache.royale.compiler.tree.mxml.IMXMLStyleSpecifierNode;
 import org.apache.royale.compiler.tree.mxml.IMXMLUintNode;
 import org.apache.royale.compiler.tree.mxml.IMXMLVectorNode;
+import org.apache.royale.compiler.tree.mxml.IMXMLWebServiceNode;
+import org.apache.royale.compiler.tree.mxml.IMXMLWebServiceOperationNode;
 import org.apache.royale.compiler.visitor.IBlockWalker;
 import org.apache.royale.compiler.visitor.mxml.IMXMLBlockWalker;
 
@@ -435,5 +437,17 @@ public class MXMLEmitter extends Emitter implements IMXMLEmitter
 		// TODO Auto-generated method stub
 		
 	}
+
+	@Override
+	public void emitWebServiceMethod(IMXMLWebServiceOperationNode node) {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public void emitWebService(IMXMLWebServiceNode node) {
+		// TODO Auto-generated method stub
+		
+	}
     
 }
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/royale/MXMLRoyaleEmitter.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/royale/MXMLRoyaleEmitter.java
index e06efba..7b2b8f5 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/royale/MXMLRoyaleEmitter.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/royale/MXMLRoyaleEmitter.java
@@ -3401,4 +3401,121 @@ public class MXMLRoyaleEmitter extends MXMLEmitter implements
 			}
 		}
 	}
+	
+	@Override
+	public void emitWebServiceMethod(IMXMLWebServiceOperationNode node) {
+        MXMLDescriptorSpecifier currentInstance = getCurrentDescriptor("i");
+        String propName = null;
+        int l = node.getChildCount();
+        for (int k = 0; k < l; k++)
+        {
+        	IASNode child = node.getChild(k);
+        	if (child.getNodeID() == ASTNodeID.MXMLPropertySpecifierID)
+        	{
+        		IMXMLPropertySpecifierNode propNode = (IMXMLPropertySpecifierNode)child;
+        		if (propNode.getName().equals("name"))
+        		{
+        			// assume StringNode with LiteralNode
+        			IMXMLStringNode literalNode = (IMXMLStringNode)propNode.getChild(0);
+        			propName = literalNode.getValue();
+        			break;
+        		}
+        	}
+        }
+    	MXMLDescriptorSpecifier propertySpecifier = new MXMLDescriptorSpecifier();
+    	propertySpecifier.isProperty = true;
+    	propertySpecifier.name = propName;
+    	propertySpecifier.parent = currentInstance;
+    	currentInstance.propertySpecifiers.add(propertySpecifier);
+        moveDown(false, null, propertySpecifier);
+
+		emitInstance(node);
+
+		moveUp(false, false);
+    	// build out the argument list if any
+    	int n = node.getChildCount();
+    	for (int i = 0; i < n; i++)
+    	{
+    		IASNode childNode = node.getChild(i);
+    		if (childNode.getNodeID() == ASTNodeID.MXMLPropertySpecifierID)
+    		{
+    			IMXMLPropertySpecifierNode propNode = (IMXMLPropertySpecifierNode)childNode;
+    			if (propNode.getName().equals("arguments"))
+    			{
+    				ArrayList<String> argList = new ArrayList<String>();
+    				childNode = propNode.getChild(0); // this is an MXMLObjectNode
+    				n = childNode.getChildCount();
+    				for (i = 0; i < n; i++)
+    				{
+    					IASNode argNode = childNode.getChild(i);
+    					propNode = (IMXMLPropertySpecifierNode)argNode;
+    					argList.add(propNode.getName());
+    				}
+    				if (argList.size() > 0)
+    				{
+    					StringBuilder list = new StringBuilder();
+    					list.append("[");
+    					int m = argList.size();
+    					for (int j = 0; j < m; j++)
+    					{
+    						if (j > 0)
+    							list.append(",");
+    						list.append("'" + argList.get(j) + "'");
+    					}
+    					list.append("]");
+
+    			        MXMLDescriptorSpecifier operationInstance = propertySpecifier.propertySpecifiers.get(0);
+
+    			        MXMLDescriptorSpecifier argListSpecifier = new MXMLDescriptorSpecifier();
+    			        argListSpecifier.isProperty = true;
+    			        argListSpecifier.name = "argumentNames";
+    			        argListSpecifier.parent = operationInstance;
+    			        argListSpecifier.value = list.toString();
+				        if (operationInstance != null)
+				        	operationInstance.propertySpecifiers.add(argListSpecifier);
+    				}
+    				break;
+    			}
+    		}
+    	}
+	}
+
+	@Override
+	public void emitWebService(IMXMLWebServiceNode node) {
+		emitInstance(node);
+		// now search for Operations, and add an Object that contains them
+		int n = node.getChildCount();
+		MXMLDescriptorSpecifier objectSpecifier = null;
+		MXMLDescriptorSpecifier propertySpecifier = null;
+		for (int i = 0; i < n; i++)
+		{
+			IASNode child = node.getChild(i);
+			if (child.getNodeID() == ASTNodeID.MXMLWebServiceOperationID)
+			{
+		        MXMLDescriptorSpecifier currentPropertySpecifier = getCurrentDescriptor("ps");
+		        MXMLDescriptorSpecifier currentInstance =
+		        	currentPropertySpecifier.propertySpecifiers.get(currentPropertySpecifier.propertySpecifiers.size() - 1);
+
+		        if (objectSpecifier == null)
+		        {
+		        	propertySpecifier = new MXMLDescriptorSpecifier();
+		        	propertySpecifier.isProperty = true;
+		        	propertySpecifier.name = "operations";
+		        	propertySpecifier.parent = currentInstance;
+
+			        if (currentInstance != null)
+			        	currentInstance.propertySpecifiers.add(propertySpecifier);
+			        objectSpecifier = new MXMLDescriptorSpecifier();
+			        objectSpecifier.isProperty = false;
+			        objectSpecifier.name = formatQualifiedName(IASLanguageConstants.Object);
+			        objectSpecifier.parent = propertySpecifier;
+			        propertySpecifier.propertySpecifiers.add(objectSpecifier);
+			        instances.add(objectSpecifier);
+		        }
+	            moveDown(false, objectSpecifier, null);
+                getMXMLWalker().walk(child); // RemoteObjectMethod
+	            moveUp(false, true);
+			}
+		}
+	}
 }
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/visitor/mxml/MXMLNodeSwitch.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/visitor/mxml/MXMLNodeSwitch.java
index 5caf3ef..3317f49 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/visitor/mxml/MXMLNodeSwitch.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/visitor/mxml/MXMLNodeSwitch.java
@@ -48,6 +48,8 @@ import org.apache.royale.compiler.tree.mxml.IMXMLStyleNode;
 import org.apache.royale.compiler.tree.mxml.IMXMLStyleSpecifierNode;
 import org.apache.royale.compiler.tree.mxml.IMXMLUintNode;
 import org.apache.royale.compiler.tree.mxml.IMXMLVectorNode;
+import org.apache.royale.compiler.tree.mxml.IMXMLWebServiceNode;
+import org.apache.royale.compiler.tree.mxml.IMXMLWebServiceOperationNode;
 import org.apache.royale.compiler.visitor.IASNodeStrategy;
 import org.apache.royale.compiler.visitor.IBlockVisitor;
 import org.apache.royale.compiler.visitor.mxml.IMXMLBlockVisitor;
@@ -164,6 +166,12 @@ public class MXMLNodeSwitch implements IASNodeStrategy
         case MXMLRemoteObjectMethodID:
             visitor.visitRemoteObjectMethod((IMXMLRemoteObjectMethodNode) node);
             break;
+        case MXMLWebServiceID:
+            visitor.visitWebService((IMXMLWebServiceNode) node);
+            break;
+        case MXMLWebServiceOperationID:
+            visitor.visitWebServiceMethod((IMXMLWebServiceOperationNode) node);
+            break;
         case MXMLApplicationID:
         case MXMLBindingAttributeID:
         case MXMLClassID:
@@ -183,8 +191,6 @@ public class MXMLNodeSwitch implements IASNodeStrategy
         case MXMLReparentID:
         //case MXMLRepeaterID:
         case MXMLResourceID:
-        case MXMLWebServiceID:
-        case MXMLWebServiceOperationID:
         default:
             throw new IllegalArgumentException(
                     "No handler specified for nodes of type '"
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/visitor/mxml/IMXMLBlockVisitor.java b/compiler-jx/src/main/java/org/apache/royale/compiler/visitor/mxml/IMXMLBlockVisitor.java
index 4507a9c..fd8af60 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/visitor/mxml/IMXMLBlockVisitor.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/visitor/mxml/IMXMLBlockVisitor.java
@@ -48,6 +48,8 @@ import org.apache.royale.compiler.tree.mxml.IMXMLStyleNode;
 import org.apache.royale.compiler.tree.mxml.IMXMLStyleSpecifierNode;
 import org.apache.royale.compiler.tree.mxml.IMXMLUintNode;
 import org.apache.royale.compiler.tree.mxml.IMXMLVectorNode;
+import org.apache.royale.compiler.tree.mxml.IMXMLWebServiceNode;
+import org.apache.royale.compiler.tree.mxml.IMXMLWebServiceOperationNode;
 import org.apache.royale.compiler.units.ICompilationUnit;
 import org.apache.royale.compiler.visitor.IBlockVisitor;
 
@@ -143,4 +145,8 @@ public interface IMXMLBlockVisitor extends IBlockVisitor
     void visitRemoteObjectMethod(IMXMLRemoteObjectMethodNode node);
 
 	void visitRemoteObject(IMXMLRemoteObjectNode node);
+
+	void visitWebServiceMethod(IMXMLWebServiceOperationNode node);
+
+	void visitWebService(IMXMLWebServiceNode node);
 }