You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by jo...@apache.org on 2019/11/21 22:43:27 UTC

[royale-compiler] branch develop updated: ASParser: definitions that are gated by a config condition are now added to a ConfigConditionBlockNode so that they appear in the AST

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

joshtynjala 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 e55d8ad  ASParser: definitions that are gated by a config condition are now added to a ConfigConditionBlockNode so that they appear in the AST
e55d8ad is described below

commit e55d8ad47a5d49e15f11ccbb9eba88e4347e05bc
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Thu Nov 21 14:24:15 2019 -0800

    ASParser: definitions that are gated by a config condition are now added to a ConfigConditionBlockNode so that they appear in the AST
    
    Like other uses of ConfigConditionBlockNode, these definitions won't appear in the compiled output. However, this keeps them in the AST, which can be useful for tooling (like IDEs) to understand that the code exists, but is disabled.
---
 .../royale/compiler/internal/parsing/as/ASParser.g    | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

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 0e47a0b..b099f3f 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
@@ -182,6 +182,11 @@ attributedDefinition[ContainerNode c]
     List<INamespaceDecorationNode> namespaceAttributes = new ArrayList<INamespaceDecorationNode>();
     List<ModifierNode> modifiers = new ArrayList<ModifierNode>(); 
     INamespaceDecorationNode namespaceAttr = null;
+	IASNode lastChild = null;
+	if(c.getChildCount() > 0)
+	{
+		lastChild = c.getChild(c.getChildCount() - 1);
+	}
     
     boolean enabled = isDefinitionEnabled(c);
     boolean eval = true;
@@ -193,7 +198,19 @@ attributedDefinition[ContainerNode c]
         	// type. If either is evaluated to false, the definition is disabled.
         	enabled &= eval;
             if (!enabled)
-			    c = new ContainerNode(); 
+			{
+				// previously, we removed the entire definition from the AST,
+				// but some IDEs can "fade out" disabled definitions. by adding
+				// the children to a ConfigConditionBlockNode, they can be seen
+				// in the AST, but ignored when generating compiled output. -JT
+			    ConfigConditionBlockNode configBlock = new ConfigConditionBlockNode(false); 
+				if(lastChild != null && c.getRemovedConditionalCompileNode())
+				{
+					configBlock.startBefore(lastChild);
+				}
+				c.addItem(configBlock);
+				c = configBlock;
+			}
         }
         (attribute[modifiers, namespaceAttributes])* 
         {