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 2018/07/30 21:58:02 UTC
[royale-compiler] branch develop updated: handle conditional
compile subtitutions in type declarations and fix error reporting line
numbers for those substitutions
This is an automated email from the ASF dual-hosted git repository.
aharui pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git
The following commit(s) were added to refs/heads/develop by this push:
new ce9a250 handle conditional compile subtitutions in type declarations and fix error reporting line numbers for those substitutions
ce9a250 is described below
commit ce9a250d2b80007fa7bfcdc6e0145aaeecd764b7
Author: Alex Harui <ah...@apache.org>
AuthorDate: Mon Jul 30 14:57:48 2018 -0700
handle conditional compile subtitutions in type declarations and fix error reporting line numbers for those substitutions
---
.../royale/compiler/internal/parsing/as/ASParser.g | 42 +++++++++++++++++++++-
.../compiler/internal/parsing/as/BaseASParser.java | 2 +-
.../internal/parsing/as/ConfigProcessor.java | 11 ++++--
3 files changed, 51 insertions(+), 4 deletions(-)
diff --git a/compiler/src/main/antlr/org/apache/royale/compiler/internal/parsing/as/ASParser.g b/compiler/src/main/antlr/org/apache/royale/compiler/internal/parsing/as/ASParser.g
index 6a38b55..6a7ac9c 100644
--- a/compiler/src/main/antlr/org/apache/royale/compiler/internal/parsing/as/ASParser.g
+++ b/compiler/src/main/antlr/org/apache/royale/compiler/internal/parsing/as/ASParser.g
@@ -2037,10 +2037,31 @@ type returns [ExpressionNodeBase n]
n = null;
}
: n=starLiteral
+ | n=configConditionAsType
| n=restrictedName ( n=typeApplication[n] )?
;
exception catch [RecognitionException ex] { n = handleMissingIdentifier(ex); }
+configConditionAsType returns [ExpressionNodeBase n]
+{
+ n = null;
+}
+ : ns:TOKEN_NAMESPACE_NAME op:TOKEN_OPERATOR_NS_QUALIFIER id:TOKEN_IDENTIFIER
+ { final NamespaceIdentifierNode nsNode = new NamespaceIdentifierNode((ASToken)ns);
+ nsNode.setIsConfigNamespace(isConfigNamespace(nsNode));
+ final IdentifierNode idNode = new IdentifierNode((ASToken)id);
+ n = transformToNSAccessExpression(nsNode, (ASToken) op, idNode);
+ n = n.copyForInitializer(null);
+ n.setSourcePath(nsNode.getSourcePath());
+ n.setLine(nsNode.getLine());
+ n.setColumn(nsNode.getColumn());
+ n.setEndLine(idNode.getEndLine());
+ n.setEndColumn(idNode.getEndColumn());
+ n.setStart(nsNode.getStart());
+ n.setEnd(idNode.getEnd());
+ }
+ ;
+
/**
* Matches a "type application" part>
*
@@ -2999,7 +3020,26 @@ propertyAccessExpression [ExpressionNodeBase l] returns [ExpressionNodeBase n]
| TOKEN_OPERATOR_DESCENDANT_ACCESS r=accessPart
{ n = new MemberAccessExpressionNode(l, op, r); }
| TOKEN_OPERATOR_NS_QUALIFIER r=nsAccessPart
- { n = transformToNSAccessExpression(l, op, r); }
+ { if (l instanceof NamespaceIdentifierNode)
+ {
+ final NamespaceIdentifierNode nsNode = (NamespaceIdentifierNode)l;
+ nsNode.setIsConfigNamespace(isConfigNamespace(nsNode));
+ final IdentifierNode idNode = (IdentifierNode)r;
+ n = transformToNSAccessExpression(nsNode, (ASToken) op, idNode);
+ n = n.copyForInitializer(null);
+ n.setSourcePath(nsNode.getSourcePath());
+ n.setLine(nsNode.getLine());
+ n.setColumn(nsNode.getColumn());
+ n.setEndLine(idNode.getEndLine());
+ n.setEndColumn(idNode.getEndColumn());
+ n.setStart(nsNode.getStart());
+ n.setEnd(idNode.getEnd());
+ }
+ else
+ {
+ n = transformToNSAccessExpression(l, (ASToken) op, r);
+ }
+ }
| n=bracketExpression[l]
| n=typeApplication[l]
;
diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/BaseASParser.java b/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/BaseASParser.java
index aff02fa..a8c3d7f 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/BaseASParser.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/BaseASParser.java
@@ -826,7 +826,7 @@ abstract class BaseASParser extends LLkParser implements IProblemReporter
/**
* Config processor used to handle config namespace expressions
*/
- private ConfigProcessor configProcessor;
+ protected ConfigProcessor configProcessor;
/**
* Determines if we should allowe errors. Used in conditional compilation to
diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/ConfigProcessor.java b/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/ConfigProcessor.java
index 143e434..2cef61d 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/ConfigProcessor.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/ConfigProcessor.java
@@ -381,7 +381,8 @@ public class ConfigProcessor
{
ConfigConstNode.ConfigDefinition cdef = (ConfigConstNode.ConfigDefinition)def;
IExpressionNode initializer = cdef.getInitializer();
- if (initializer.getNodeID() != ASTNodeID.MemberAccessExpressionID)
+ if (initializer.getNodeID() != ASTNodeID.MemberAccessExpressionID &&
+ initializer.getNodeID() != ASTNodeID.IdentifierID)
{
// Get the real source node for the problem.
// If there isn't one, then don't make a problem - assume
@@ -441,7 +442,8 @@ public class ConfigProcessor
{
ConfigConstNode.ConfigDefinition def = (ConfigConstNode.ConfigDefinition)definition;
IExpressionNode initializer = def.getInitializer();
- if (initializer.getNodeID() == ASTNodeID.MemberAccessExpressionID)
+ if (initializer.getNodeID() == ASTNodeID.MemberAccessExpressionID ||
+ initializer.getNodeID() == ASTNodeID.IdentifierID)
return initializer;
}
@@ -504,6 +506,11 @@ public class ConfigProcessor
MemberAccessExpressionNode mae = (MemberAccessExpressionNode)result;
return mae;
}
+ else if (result instanceof IdentifierNode)
+ {
+ IdentifierNode id = (IdentifierNode)result;
+ return id;
+ }
return null;
}