예제 #1
0
            public override IAstNode Visit(ElementAccess node)
            {
                var name = node.Target as SimpleName;
                if (name != null && name.Name == "Variables" && node.Indices.Count == 1)
                {
                    var indexExp = node.Indices[0] as IntegerLiteralExpression;
                    if (indexExp != null)
                    {
                        var index = indexExp.Value;
                        if ((index & 0xF0000000) == 0)
                        {
                            return node;
                        }

                        if ((index & 0x80000000) != 0)
                        {
                            index &= 0x7FFFFFFF;
                            return new ElementAccess("Bits", index);
                        }

                        if ((index & 0x40000000) != 0)
                        {
                            index &= 0xFFFFFFF;
                            return new ElementAccess("Locals", index);
                        }
                    }
                }
                return base.Visit(node);
            }
예제 #2
0
            public override IAstNode Visit(ElementAccess node)
            {
                var name = node.Target as SimpleName;

                if (name != null && name.Name == "Variables" && node.Indices.Count == 1)
                {
                    var indexExp = node.Indices[0] as IntegerLiteralExpression;
                    if (indexExp != null)
                    {
                        var index = indexExp.Value;
                        if ((index & 0xF0000000) == 0)
                        {
                            return(node);
                        }

                        if ((index & 0x80000000) != 0)
                        {
                            index &= 0x7FFFFFFF;
                            return(new ElementAccess("Bits", index));
                        }

                        if ((index & 0x40000000) != 0)
                        {
                            index &= 0xFFFFFFF;
                            return(new ElementAccess("Locals", index));
                        }
                    }
                }
                return(base.Visit(node));
            }
예제 #3
0
 /// <summary>
 /// Initializes a new instance of the CodeBlock class.
 /// </summary>
 /// <param name="access">The block's access level.</param>
 /// <param name="placement">The block's placement.</param>
 /// <param name="name">The name of the block</param>
 /// <param name="body">The body of the code block.</param>
 public CodeBlock(ElementAccess access, ElementType placement, string name, string body)
 {
     Name      = name;
     Access    = access;
     Body      = body;
     Placement = placement;
     Weight    = 0;
 }
예제 #4
0
        /// <summary>
        /// Evaluates an element into a codeblock
        /// </summary>
        /// <param name="parentElement">The parent element, containing the given element</param>
        /// <param name="element">The element to evaluate</param>
        /// <param name="newStartPoint">The starting point for the element</param>
        /// <returns>A CodeBlock derived from the Element with appropriate placement and access set</returns>
        private CodeBlock EvaluateBlock(CodeElement parentElement, CodeElement element, ref EditPoint newStartPoint)
        {
            CodeBlock     currentBlock  = null;
            ElementType   blockType     = GetType(element);
            bool          blockStatic   = GetElementIsStatic(element);
            bool          blockConstant = GetElementIsConstant(element);
            string        body          = GetCodeBlockText(parentElement, element, out newStartPoint);
            ElementAccess blockAccess   = GetAccess(element, blockConstant, blockStatic);
            int           weight        = GetWeight(element);

            currentBlock = new CodeBlock(blockAccess, blockType, element.Name, body);
            return(currentBlock);
        }
예제 #5
0
        public override void visit_element_access(ElementAccess expr)
        {
            if (expr.container is MemberAccess && expr.container.symbol_reference is Signal)
            {
                if (expr.parent_node is MethodCall)
                {
                    // detailed signal emission
                    var sig = (Signal)expr.symbol_reference;
                    var ma  = (MemberAccess)expr.container;

                    var detail_expr = expr.get_indices()[0];

                    CCodeFunctionCall ccall;
                    if (!sig.external_package && expr.source_reference.file == sig.source_reference.file)
                    {
                        var detail_cexpr = get_detail_cexpression(detail_expr, expr);

                        ccall = new CCodeFunctionCall(new CCodeIdentifier("g_signal_emit"));
                        ccall.add_argument(get_cvalue(ma.inner));
                        ccall.add_argument(get_signal_id_cexpression(sig));
                        if (detail_cexpr != null)
                        {
                            ccall.add_argument(detail_cexpr);
                        }
                    }
                    else
                    {
                        var signal_name_cexpr = get_signal_name_cexpression(sig, detail_expr, expr);

                        ccall = new CCodeFunctionCall(new CCodeIdentifier("g_signal_emit_by_name"));
                        ccall.add_argument(get_cvalue(ma.inner));
                        if (signal_name_cexpr != null)
                        {
                            ccall.add_argument(signal_name_cexpr);
                        }
                    }

                    set_cvalue(expr, ccall);
                }
                else
                {
                    // signal connect or disconnect
                }
            }
            else
            {
                base.visit_element_access(expr);
            }
        }
예제 #6
0
 public override IAstNode Visit(ElementAccess node)
 {
     var name = node.Target as SimpleName;
     if (name != null && name.Name == "Variables" && node.Indices.Count == 1)
     {
         var index = node.Indices[0] as IntegerLiteralExpression;
         if (index != null)
         {
             if (KnownVariables.ContainsKey(index.Value))
             {
                 return new SimpleName(KnownVariables[index.Value]);
             }
         }
     }
     return new ElementAccess((Expression)node.Target.Accept(this), node.Indices.Select(idx => (Expression)idx.Accept(this)));
 }
예제 #7
0
        /// <summary>
        /// Evaluates the appropriate access to use
        /// </summary>
        /// <param name="access">The visual studio access enum</param>
        /// <param name="isConstant">Whether the element is constant</param>
        /// <param name="isStatic">Whether the element is static</param>
        /// <returns>The appropriate access used for ordering</returns>
        private ElementAccess EvaluateAccess(vsCMAccess access, bool isConstant, bool isStatic)
        {
            ElementAccess elementAccess = accessLookup[access];

            if (isConstant)
            {
                elementAccess = (ElementAccess)Enum.Parse(typeof(ElementAccess), elementAccess.ToString() + "_CONSTANT");
            }

            if (isStatic)
            {
                elementAccess = (ElementAccess)Enum.Parse(typeof(ElementAccess), elementAccess.ToString() + "_STATIC");
            }

            return(elementAccess);
        }
예제 #8
0
        public void VisitElementAccess(ElementAccess node)
        {
            var arrayType = InferType(node.Array, _context) as ArrayType;
            var indexType = InferType(node.Index, _context);

            if (arrayType == null)
            {
                throw new TypeInferenceException("Array access expression must be type array");
            }
            if (indexType != KnownType.Int32)
            {
                throw new TypeInferenceException("Array element index must be only type int32");
            }

            _type = indexType;
        }
예제 #9
0
        public override void visit_element_access(ElementAccess expr)
        {
            List <Expression> indices = expr.get_indices();
            int rank = indices.Count;

            var ccontainer = get_cvalue(expr.container);
            var cindex     = get_cvalue(indices[0]);

            if (expr.container.symbol_reference is ArrayLengthField)
            {
                /* Figure if cindex is a constant expression and calculate dim...*/
                var lit          = indices[0] as IntegerLiteral;
                var memberaccess = expr.container as MemberAccess;
                if (lit != null && memberaccess != null)
                {
                    int dim = int.Parse(lit.value);
                    set_cvalue(expr, get_array_length_cexpression(memberaccess.inner, dim + 1));
                }
                else
                {
                    Report.error(expr.source_reference, "only integer literals supported as index");
                }
            }
            else
            {
                // access to element in an array
                for (int i = 1; i < rank; i++)
                {
                    var cmul = new CCodeBinaryExpression(CCodeBinaryOperator.MUL, cindex, get_array_length_cexpression(expr.container, i + 1));
                    cindex = new CCodeBinaryExpression(CCodeBinaryOperator.PLUS, cmul, get_cvalue(indices[i]));
                }
                set_cvalue(expr, new CCodeElementAccess(ccontainer, cindex));
            }

            expr.target_value.value_type = expr.value_type.copy();
            if (!expr.lvalue)
            {
                expr.target_value = store_temp_value(expr.target_value, expr);
            }
            ((GLibValue)expr.target_value).lvalue = true;
        }
예제 #10
0
 public virtual void Visit(ElementAccess node)
 {
     DefaultVisit(node);
 }
예제 #11
0
 /// <summary>
 /// Visit operation called for element access expressions.
 ///
 /// <param name="expr">an element access expression</param>
 /// </summary>
 public virtual void visit_element_access(ElementAccess expr)
 {
 }
예제 #12
0
 public virtual void Visit(ElementAccess node)
 {
     DefaultVisit(node);
 }
예제 #13
0
        Statement ActorOps()
        {
            var convertTable = new byte[] { 1, 0, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 20 };
            Expression actor = new ElementAccess("Actors", GetVarOrDirectByte(OpCodeParameter.Param1));
            while ((_opCode = ReadByte()) != 0xFF)
            {
                if (Game.Version < 5)
                {
                    _opCode = ((_opCode & 0xE0) | convertTable[(_opCode & 0x1F) - 1]);
                }
                switch (_opCode & 0x1F)
                {
                    case 0:
                        {
                            /*						 dummy case */
                            var dummy = GetVarOrDirectByte(OpCodeParameter.Param1);
                            actor = new MethodInvocation(
                                new MemberAccess(actor, 
                                    "ActorOpUnk0"))
                                        .AddArgument(dummy);
                            break;
                        }
                    case 1:
                        {         // SO_COSTUME
                            var cost = GetVarOrDirectByte(OpCodeParameter.Param1);
                            actor = new MethodInvocation(new MemberAccess(actor, "Costume")).AddArgument(cost);
                        }
                        break;

                    case 2:
                        {         // SO_STEP_DIST
                            var i = GetVarOrDirectByte(OpCodeParameter.Param1);
                            var j = GetVarOrDirectByte(OpCodeParameter.Param2);
                            actor = new MethodInvocation(new MemberAccess(actor, "SetWalkSpeed")).AddArguments(i, j);
                        }
                        break;

                    case 3:
                        {         // SOSound
                            var sound = GetVarOrDirectByte(OpCodeParameter.Param1);
                            actor = new MethodInvocation(new MemberAccess(actor, "SetSound")).AddArgument(sound);
                        }
                        break;
                    case 4:
                        {         // SO_WALK_ANIMATION
                            var walkFrame = GetVarOrDirectByte(OpCodeParameter.Param1);
                            actor = new MethodInvocation(new MemberAccess(actor, "SetWalkAnimation")).AddArgument(walkFrame);
                        }
                        break;

                    case 5:
                        {        // SO_TALK_ANIMATION
                            var talkStartFrame = GetVarOrDirectByte(OpCodeParameter.Param1);
                            var talkStopFrame = GetVarOrDirectByte(OpCodeParameter.Param2);
                            actor = new MethodInvocation(new MemberAccess(actor, "SetTalkAnimation")).AddArguments(talkStartFrame, talkStopFrame);
                        }
                        break;

                    case 6:
                        {        // SO_STAND_ANIMATION
                            var standFrame = GetVarOrDirectByte(OpCodeParameter.Param1);
                            actor = new MethodInvocation(new MemberAccess(actor, "SetStandAnimation")).AddArgument(standFrame);
                        }
                        break;

                    case 7:
                        {         // SO_ANIMATION
                            var i = GetVarOrDirectByte(OpCodeParameter.Param1);
                            var j = GetVarOrDirectByte(OpCodeParameter.Param2);
                            var k = GetVarOrDirectByte(OpCodeParameter.Param3);
                            actor = new MethodInvocation(new MemberAccess(actor, "SetAnimation")).AddArguments(i, j, k);
                        }
                        break;

                    case 8:         // SO_DEFAULT
                        actor = new MethodInvocation(new MemberAccess(actor, "SetDefaultAnimation"));
                        break;

                    case 9:
                        {       // SO_ELEVATION
                            var elevation = GetVarOrDirectWord(OpCodeParameter.Param1);
                            actor = new MethodInvocation(new MemberAccess(actor, "SetElevation")).AddArgument(elevation);
                        }
                        break;

                    case 10:        // SO_ANIMATION_DEFAULT
                        actor = new MethodInvocation(new MemberAccess(actor, "ResetAnimation"));
                        break;

                    case 11:
                        {       // SO_PALETTE
                            var i = GetVarOrDirectByte(OpCodeParameter.Param1);
                            var j = GetVarOrDirectByte(OpCodeParameter.Param2);
                            actor = new MethodInvocation(new MemberAccess(actor, "SetPalette")).AddArguments(i, j);
                        }
                        break;

                    case 12:
                        {       // SO_TALK_COLOR
                            var talkColor = GetVarOrDirectByte(OpCodeParameter.Param1);
                            actor = new MethodInvocation(new MemberAccess(actor, "SetTalkColor")).AddArgument(talkColor);
                        }
                        break;

                    case 13:
                        {        // SO_ACTOR_NAME
                            var name = ReadCharacters();
                            actor = new MethodInvocation(new MemberAccess(actor, "SetName")).AddArgument(name);
                        }
                        break;

                    case 14:
                        {       // SO_INIT_ANIMATION
                            var initFrame = GetVarOrDirectByte(OpCodeParameter.Param1);
                            actor = new MethodInvocation(new MemberAccess(actor, "SetInitAnimation")).AddArgument(initFrame);
                        }
                        break;

                    case 16:
                        {        // SO_ACTOR_WIDTH
                            var width = GetVarOrDirectByte(OpCodeParameter.Param1);
                            actor = new MethodInvocation(new MemberAccess(actor, "Width")).AddArgument(width);
                        }
                        break;

                    case 17:
                        {       // SO_ACTOR_SCALE
                            var args = new List<Expression>();
                            if (Game.Version == 4)
                            {
                                var arg = GetVarOrDirectByte(OpCodeParameter.Param1);
                                args.Add(arg);
                                args.Add(arg);
                            }
                            else
                            {
                                args.Add(GetVarOrDirectByte(OpCodeParameter.Param1));
                                args.Add(GetVarOrDirectByte(OpCodeParameter.Param2));
                            }
                            actor = new MethodInvocation(new MemberAccess(actor, "Scale")).AddArguments(args);
                        }
                        break;

                    case 18:
                        {       // SO_NEVER_ZCLIP
                            actor = new MethodInvocation(new MemberAccess(actor, "NeverZClip"));
                        }
                        break;

                    case 19:
                        {       // SO_ALWAYS_ZCLIP
                            var clip = GetVarOrDirectByte(OpCodeParameter.Param1);
                            actor = new MethodInvocation(new MemberAccess(actor, "ForceCLip")).AddArgument(clip);
                        }
                        break;

                    case 20:        // SO_IGNORE_BOXES
                    case 21:
                        {       // SO_FOLLOW_BOXES
                            var ignoreBoxes = (_opCode & 1) == 0;
                            actor = new MethodInvocation(new MemberAccess(actor, "IgnoreBoxes")).AddArgument(ignoreBoxes.ToLiteral());
                        }
                        break;

                    case 22:
                        {       // SO_ANIMATION_SPEED
                            var animSpeed = GetVarOrDirectByte(OpCodeParameter.Param1);
                            actor = new MethodInvocation(new MemberAccess(actor, "AnimationSpeed")).AddArgument(animSpeed);
                        }
                        break;

                    case 23:
                        {        // SO_SHADOW
                            var shadowMode = GetVarOrDirectByte(OpCodeParameter.Param1);
                            actor = new MethodInvocation(new MemberAccess(actor, "ShadowMode")).AddArgument(shadowMode);
                        }
                        break;

                    default:
                        throw new NotImplementedException(string.Format("ActorOps #{0} is not yet implemented, sorry :(", _opCode & 0x1F));
                }
            }
            return actor.ToStatement();
        }
예제 #14
0
void case_492()
#line 4160 "ps-parser.jay"
{
	    var newExpr = yyVals[-3+yyTop] as AsNew;
	    if (newExpr != null) {
		    /* Convert ElementAccess(AsNew()) into AsNew(ElementAccess())*/
			var elemAccessExpr = new ElementAccess(newExpr.Expr, (Arguments) yyVals[-1+yyTop], GetLocation (yyVals[-2+yyTop]));
			newExpr.Expr = elemAccessExpr;
			yyVal = newExpr;
	    } else {
			yyVal = new ElementAccess ((Expression) yyVals[-3+yyTop], (Arguments) yyVals[-1+yyTop], GetLocation (yyVals[-2+yyTop]));
		}
		lbag.AddLocation (yyVal, GetLocation (yyVals[0+yyTop]));
	  }
예제 #15
0
void case_528()
#line 3883 "cs-parser.jay"
{
		Error_SyntaxError (yyToken);
		yyVal = new ElementAccess ((Expression) yyVals[-2+yyTop], null, GetLocation (yyVals[-1+yyTop]));
	  }
예제 #16
0
void case_526()
#line 3867 "cs-parser.jay"
{
		if (lang_version < LanguageVersion.V_6)
			FeatureIsNotAvailable (GetLocation (yyVals[-3+yyTop]), "null propagating operator");

		yyVal = new ElementAccess ((Expression) yyVals[-4+yyTop], (Arguments) yyVals[-1+yyTop], GetLocation (yyVals[-2+yyTop])) {
			ConditionalAccess = true
		};

		lbag.AddLocation (yyVal, GetLocation (yyVals[-3+yyTop]), GetLocation (yyVals[0+yyTop]));
	  }
예제 #17
0
		public virtual object Visit (ElementAccess elementAccessExpression)
		{
			return null;
		}
예제 #18
0
 public override void visit_element_access(ElementAccess expr)
 {
     expr.accept_children(this);
 }
예제 #19
0
 public virtual void VisitElementAccess(ElementAccess node)
 {
     node.Expression.Accept(this);
     node.ArgumentList.Accept(this);
 }
예제 #20
0
 public void VisitElementAccess(ElementAccess node)
 {
     node.Array.Accept(this);
     node.Index.Accept(this);
     _emitter.Emit(OpCodes.Ldelem_I4);
 }
예제 #21
0
void case_525()
#line 3862 "cs-parser.jay"
{
		yyVal = new ElementAccess ((Expression) yyVals[-3+yyTop], (Arguments) yyVals[-1+yyTop], GetLocation (yyVals[-2+yyTop]));
		lbag.AddLocation (yyVal, GetLocation (yyVals[0+yyTop]));
	  }
예제 #22
0
void case_537()
#line 3946 "cs-parser.jay"
{
	  	Error_SyntaxError (yyToken);
		yyVal = new ElementAccess (null, null, GetLocation (yyVals[-1+yyTop]));
	  }
예제 #23
0
void case_527()
#line 3878 "cs-parser.jay"
{
		Error_SyntaxError (yyToken);
		yyVal = new ElementAccess ((Expression) yyVals[-3+yyTop], (Arguments) yyVals[-1+yyTop], GetLocation (yyVals[-2+yyTop]));
	  }
			public override object Visit (ElementAccess elementAccessExpression)
			{
				IndexerExpression result = new IndexerExpression ();
				var location = LocationsBag.GetLocations (elementAccessExpression);
				
				if (elementAccessExpression.Expr != null)
					result.AddChild ((Expression)elementAccessExpression.Expr.Accept (this), Roles.TargetExpression);
				result.AddChild (new CSharpTokenNode (Convert (elementAccessExpression.Location), Roles.LBracket), Roles.LBracket);
				AddArguments (result, location, elementAccessExpression.Arguments);
				if (location != null)
					result.AddChild (new CSharpTokenNode (Convert (location [0]), Roles.RBracket), Roles.RBracket);
				return result;
			}
예제 #25
0
void case_536()
#line 3941 "cs-parser.jay"
{
	  	yyVal = new ElementAccess (new BaseThis (GetLocation (yyVals[-3+yyTop])), (Arguments) yyVals[-1+yyTop], GetLocation (yyVals[-2+yyTop]));
		lbag.AddLocation (yyVal, GetLocation (yyVals[0+yyTop]));
	  }
예제 #26
0
void case_450()
#line 3842 "ps-parser.jay"
{
		var ea = new ElementAccess ((Expression) yyVals[-4+yyTop], (Arguments) yyVals[-1+yyTop], GetLocation (yyVals[-2+yyTop]));
		ea.AccessorType = ElementAccess.Accessor.AsE4xAttributeAccess;
		lbag.AddLocation (GetLocation (yyVals[-2+yyTop]), GetLocation (yyVals[0+yyTop]));
		yyVal = ea;
	  }
예제 #27
0
 /// <summary>
 /// Initializes a new instance of the CodeBlock class.
 /// </summary>
 /// <param name="access">The block's access level.</param>
 /// <param name="placement">The block's placement.</param>
 /// <param name="name">The name of the block</param>
 /// <param name="body">The body of the code block.</param>
 /// <param name="weight">An additional sort component that only applies to items that are the same access and placement.</param>
 public CodeBlock(ElementAccess access, ElementType placement, string name, string body, int weight)
     : this(access, placement, name, body)
 {
     Weight = weight;
 }
예제 #28
0
        /// <summary>
        /// Analyzes children of nodes in a particular file
        /// </summary>
        /// <param name="fileAction">The object containing the actions to run on the file</param>
        /// <param name="children">List of child nodes to check</param>
        /// <param name="level">Recursion level to avoid stack overflows</param>
        private bool AnalyzeChildren(FileActions fileAction, UstList <UstNode> children, int level, string parentNamespace = "", string parentClass = "")
        {
            bool containsActions = false;

            if (children == null || level > Constants.MaxRecursionDepth)
            {
                return(false);
            }

            foreach (var child in children)
            {
                try
                {
                    switch (child.NodeType)
                    {
                    case IdConstants.AnnotationIdName:
                    {
                        var annotation   = (Annotation)child;
                        var compareToken = new AttributeToken()
                        {
                            Key = annotation.Identifier, Namespace = annotation.Reference.Namespace, Type = annotation.SemanticClassType
                        };
                        _rootNodes.Attributetokens.TryGetValue(compareToken, out var token);
                        if (token != null)
                        {
                            AddActions(fileAction, token, child.TextSpan);
                            containsActions = true;
                        }
                        break;
                    }

                    case IdConstants.UsingDirectiveIdName:
                    {
                        var compareToken = new UsingDirectiveToken()
                        {
                            Key = child.Identifier
                        };
                        _rootNodes.Usingdirectivetokens.TryGetValue(compareToken, out var token);
                        if (token != null)
                        {
                            AddActions(fileAction, token, child.TextSpan);
                            containsActions = true;
                        }
                        break;
                    }

                    case IdConstants.NamespaceIdName:
                    {
                        var compareToken = new NamespaceToken()
                        {
                            Key = child.Identifier
                        };
                        _rootNodes.NamespaceTokens.TryGetValue(compareToken, out var token);
                        if (token != null)
                        {
                            AddActions(fileAction, token, child.TextSpan);
                            containsActions = true;
                        }
                        if (AnalyzeChildren(fileAction, child.Children, ++level, child.Identifier))
                        {
                            containsActions = true;
                        }
                        break;
                    }

                    case IdConstants.ClassIdName:
                    {
                        var classType = (ClassDeclaration)child;
                        var baseToken = new ClassDeclarationToken()
                        {
                            FullKey = classType.BaseType
                        };
                        _rootNodes.Classdeclarationtokens.TryGetValue(baseToken, out var token);

                        if (token != null)
                        {
                            //In case of class declarations, add actions on the class by name, instead of property
                            AddNamedActions(fileAction, token, classType.Identifier, child.TextSpan);
                            AddActions(fileAction, token, child.TextSpan);
                            containsActions = true;
                        }

                        token = null;
                        string name      = string.Concat(classType.Reference != null ? string.Concat(classType.Reference.Namespace, ".") : string.Empty, classType.Identifier);
                        var    nameToken = new ClassDeclarationToken()
                        {
                            FullKey = name
                        };
                        _rootNodes.Classdeclarationtokens.TryGetValue(nameToken, out token);

                        if (token != null)
                        {
                            //In case of class declarations, add actions on the class by name, instead of property
                            AddNamedActions(fileAction, token, classType.Identifier, child.TextSpan);
                            AddActions(fileAction, token, child.TextSpan);
                            containsActions = true;
                        }

                        if (AnalyzeChildren(fileAction, child.Children, ++level, parentNamespace, classType.Identifier))
                        {
                            containsActions = true;
                        }
                        break;
                    }

                    case IdConstants.InterfaceIdName:
                    {
                        var interfaceType = (InterfaceDeclaration)child;
                        var baseToken     = new InterfaceDeclarationToken()
                        {
                            FullKey = interfaceType.BaseType
                        };
                        InterfaceDeclarationToken token = null;

                        if (!string.IsNullOrEmpty(interfaceType.BaseType))
                        {
                            _rootNodes.InterfaceDeclarationTokens.TryGetValue(baseToken, out token);
                        }

                        if (token != null)
                        {
                            //In case of interface declarations, add actions on the interface by name, instead of property
                            AddNamedActions(fileAction, token, interfaceType.Identifier, child.TextSpan);
                            AddActions(fileAction, token, child.TextSpan);
                            containsActions = true;
                        }

                        token = null;
                        string name      = string.Concat(interfaceType.Reference != null ? string.Concat(interfaceType.Reference.Namespace, ".") : string.Empty, interfaceType.Identifier);
                        var    nameToken = new InterfaceDeclarationToken()
                        {
                            FullKey = name
                        };
                        _rootNodes.InterfaceDeclarationTokens.TryGetValue(nameToken, out token);

                        if (token != null)
                        {
                            //In case of interface declarations, add actions on the interface by name, instead of property
                            AddNamedActions(fileAction, token, interfaceType.Identifier, child.TextSpan);
                            AddActions(fileAction, token, child.TextSpan);
                            containsActions = true;
                        }

                        if (AnalyzeChildren(fileAction, child.Children, ++level, parentNamespace))
                        {
                            containsActions = true;
                        }
                        break;
                    }

                    case IdConstants.MethodIdName:
                    {
                        var compareToken = new MethodDeclarationToken()
                        {
                            FullKey = string.Concat(child.Identifier)
                        };
                        _rootNodes.MethodDeclarationTokens.TryGetValue(compareToken, out var token);
                        if (token != null)
                        {
                            AddNamedActions(fileAction, token, child.Identifier, child.TextSpan);
                            AddActions(fileAction, token, child.TextSpan);
                            containsActions = true;
                        }
                        if (AnalyzeChildren(fileAction, child.Children, ++level, parentNamespace, parentClass))
                        {
                            containsActions = true;
                        }
                        break;
                    }

                    case IdConstants.InvocationIdName:
                    {
                        string overrideKey = string.Empty;

                        InvocationExpression invocationExpression = (InvocationExpression)child;

                        ////If we don't have a semantic analysis, we dont want to replace invocation expressions, otherwise we'll be replacing expressions regardless of their class/namespace
                        if (string.IsNullOrEmpty(invocationExpression.SemanticOriginalDefinition))
                        {
                            break;
                        }

                        var compareToken = new InvocationExpressionToken()
                        {
                            Key = invocationExpression.SemanticOriginalDefinition, Namespace = invocationExpression.Reference.Namespace, Type = invocationExpression.SemanticClassType
                        };
                        _rootNodes.Invocationexpressiontokens.TryGetValue(compareToken, out var token);

                        //Attempt a wildcard search, if applicable. This is invocation expression specific because it has to look inside the invocation expressions only
                        if (token == null)
                        {
                            var wildcardMatches = _rootNodes.Invocationexpressiontokens.Where(i => i.Key.Contains("*"));
                            if (wildcardMatches.Any())
                            {
                                token = wildcardMatches.FirstOrDefault(i => compareToken.Key.WildcardEquals(i.Key) && compareToken.Namespace == i.Namespace && compareToken.Type == i.Type);

                                if (token != null)
                                {
                                    //We set the key so that we don't do another wildcard search during replacement, we just use the name as it was declared in the code
                                    overrideKey = compareToken.Key;
                                }
                            }
                            //If the semanticClassType is too specific to apply to all TData types
                            if (token == null)
                            {
                                if (invocationExpression.SemanticClassType.Contains('<'))
                                {
                                    string semanticClassType = invocationExpression.SemanticClassType.Substring(0, invocationExpression.SemanticClassType.IndexOf('<'));
                                    compareToken = new InvocationExpressionToken()
                                    {
                                        Key = invocationExpression.SemanticOriginalDefinition, Namespace = invocationExpression.Reference.Namespace, Type = semanticClassType
                                    };
                                    _rootNodes.Invocationexpressiontokens.TryGetValue(compareToken, out token);
                                }
                            }
                        }

                        if (token != null)
                        {
                            AddActions(fileAction, token, child.TextSpan, overrideKey);
                            containsActions = true;
                        }
                        if (AnalyzeChildren(fileAction, child.Children, ++level, parentNamespace, parentClass))
                        {
                            containsActions = true;
                        }
                        break;
                    }

                    case IdConstants.ElementAccessIdName:
                    {
                        ElementAccess elementAccess = (ElementAccess)child;
                        var           compareToken  = new ElementAccessToken()
                        {
                            Key       = elementAccess.Expression,
                            FullKey   = GetFullKey(elementAccess.Reference?.Namespace, elementAccess.SemanticClassType, elementAccess.Expression),
                            Type      = elementAccess.SemanticClassType,
                            Namespace = elementAccess.Reference?.Namespace
                        };
                        _rootNodes.ElementAccesstokens.TryGetValue(compareToken, out var token);
                        if (token != null)
                        {
                            AddActions(fileAction, token, child.TextSpan);
                            containsActions = true;
                        }
                        if (AnalyzeChildren(fileAction, child.Children, ++level, parentNamespace, parentClass))
                        {
                            containsActions = true;
                        }
                        break;
                    }

                    case IdConstants.MemberAccessIdName:
                    {
                        MemberAccess memberAccess = (MemberAccess)child;
                        var          compareToken = new MemberAccessToken()
                        {
                            Key       = memberAccess.Name,
                            FullKey   = GetFullKey(memberAccess.Reference?.Namespace, memberAccess.SemanticClassType, memberAccess.Name),
                            Type      = memberAccess.SemanticClassType,
                            Namespace = memberAccess.Reference?.Namespace
                        };
                        _rootNodes.MemberAccesstokens.TryGetValue(compareToken, out var token);
                        if (token != null)
                        {
                            AddActions(fileAction, token, child.TextSpan);
                            containsActions = true;
                        }
                        if (AnalyzeChildren(fileAction, child.Children, ++level, parentNamespace, parentClass))
                        {
                            containsActions = true;
                        }
                        break;
                    }

                    case IdConstants.DeclarationNodeIdName:
                    {
                        var declarationNode = (DeclarationNode)child;
                        var compareToken    = new IdentifierNameToken()
                        {
                            Key = string.Concat(declarationNode.Reference.Namespace, ".", declarationNode.Identifier), Namespace = declarationNode.Reference.Namespace
                        };
                        _rootNodes.Identifiernametokens.TryGetValue(compareToken, out var token);
                        if (token != null)
                        {
                            AddActions(fileAction, token, child.TextSpan);
                            containsActions = true;
                        }
                        if (AnalyzeChildren(fileAction, child.Children, ++level, parentNamespace, parentClass))
                        {
                            containsActions = true;
                        }
                        break;
                    }

                    case IdConstants.ObjectCreationIdName:
                    {
                        var objectCreationNode = (ObjectCreationExpression)child;
                        //Rules based on Object Creation Parent Hierarchy
                        var compareToken = new ObjectCreationExpressionToken()
                        {
                            Key = objectCreationNode.Identifier, Namespace = objectCreationNode.Reference?.Namespace, Type = objectCreationNode.SemanticClassType
                        };
                        _rootNodes.ObjectCreationExpressionTokens.TryGetValue(compareToken, out var token);
                        if (token != null)
                        {
                            AddActions(fileAction, token, child.TextSpan);
                            containsActions = true;
                        }

                        //Rules based on Object Creation location within code
                        var compareTokenLocation = new ObjectCreationExpressionToken()
                        {
                            Key = objectCreationNode.Identifier, Namespace = parentNamespace, Type = parentClass
                        };
                        _rootNodes.ObjectCreationExpressionTokens.TryGetValue(compareTokenLocation, out var tokenLocation);
                        if (tokenLocation != null)
                        {
                            AddActions(fileAction, tokenLocation, child.TextSpan);
                            containsActions = true;
                        }

                        token = null;
                        if (!string.IsNullOrEmpty(objectCreationNode.SemanticOriginalDefinition))
                        {
                            var nameToken = new ObjectCreationExpressionToken()
                            {
                                Key = objectCreationNode.SemanticOriginalDefinition, Namespace = objectCreationNode.SemanticNamespace, Type = objectCreationNode.SemanticClassType
                            };
                            _rootNodes.ObjectCreationExpressionTokens.TryGetValue(nameToken, out token);
                            if (token != null)
                            {
                                AddActions(fileAction, token, child.TextSpan);
                                containsActions = true;
                            }
                        }

                        if (AnalyzeChildren(fileAction, child.Children, ++level, parentNamespace, parentClass))
                        {
                            containsActions = true;
                        }
                        break;
                    }

                    default:
                    {
                        if (AnalyzeChildren(fileAction, child.Children, ++level, parentNamespace, parentClass))
                        {
                            containsActions = true;
                        }
                        break;
                    }
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.LogError(ex, "Error loading actions for item {0} of type {1}", child.Identifier, child.NodeType);
                }
            }
            return(containsActions);
        }
예제 #29
0
 public virtual object Visit(ElementAccess elementAccessExpression)
 {
     return(null);
 }
예제 #30
0
        Statement VerbOps()
        {
            Expression verb = new ElementAccess("Verbs", GetVarOrDirectByte(OpCodeParameter.Param1));

            while ((_opCode = ReadByte()) != 0xFF)
            {
                switch (_opCode & 0x1F)
                {
                    case 1:     // SO_VERB_IMAGE
                        {
                            var a = GetVarOrDirectWord(OpCodeParameter.Param1);
                            verb = new MethodInvocation(new MemberAccess(verb, "SetImage")).AddArgument(a);
                        }
                        break;

                    case 2:     // SO_VERB_NAME
                        var text = ReadCharacters();
                        verb = new MethodInvocation(new MemberAccess(verb, "SetName")).AddArgument(text);
                        break;

                    case 3:     // SO_VERB_COLOR
                        {
                            var color = GetVarOrDirectByte(OpCodeParameter.Param1);
                            verb = new MethodInvocation(new MemberAccess(verb, "SetColor")).AddArgument(color);
                        }
                        break;

                    case 4:     // SO_VERB_HICOLOR
                        var hiColor = GetVarOrDirectByte(OpCodeParameter.Param1);
                        verb = new MethodInvocation(new MemberAccess(verb, "SetHiColor")).AddArgument(hiColor);
                        break;

                    case 5:     // SO_VERB_AT
                        var left = GetVarOrDirectWord(OpCodeParameter.Param1);
                        var top = GetVarOrDirectWord(OpCodeParameter.Param2);
                        verb = new MethodInvocation(new MemberAccess(verb, "At")).AddArguments(left, top);
                        break;

                    case 6:
					// SO_VERB_ON
                        verb = new MethodInvocation(new MemberAccess(verb, "On"));
                        break;

                    case 7:
					// SO_VERB_OFF
                        verb = new MethodInvocation(new MemberAccess(verb, "Off"));
                        break;

                    case 8:     // SO_VERB_DELETE
                        verb = new MethodInvocation(new MemberAccess(verb, "Delete"));
                        break;

                    case 9:
                        {
                            // SO_VERB_NEW
                            verb = new MethodInvocation(new MemberAccess(verb, "New"));
                            break;
                        }
                    case 16:    // SO_VERB_DIMCOLOR
                        {
                            var color = GetVarOrDirectByte(OpCodeParameter.Param1);
                            verb = new MethodInvocation(new MemberAccess(verb, "SetDimColor")).AddArgument(color);
                        }
                        break;

                    case 17:    // SO_VERB_DIM
                        verb = new MethodInvocation(new MemberAccess(verb, "Dim"));
                        break;

                    case 18:    // SO_VERB_KEY
                        var key = GetVarOrDirectByte(OpCodeParameter.Param1);
                        verb = new MethodInvocation(new MemberAccess(verb, "SetKey")).AddArgument(key);
                        break;

                    case 19:    // SO_VERB_CENTER
                        verb = new MethodInvocation(new MemberAccess(verb, "Center"));
                        break;

                    case 20:    // SO_VERB_NAME_STR
                        var index = GetVarOrDirectWord(OpCodeParameter.Param1);
                        verb = new MethodInvocation(new MemberAccess(verb, "SetText")).AddArgument(new ElementAccess("Strings", index));
                        break;
                    case 22:    // assign object
                        {
                            var a = GetVarOrDirectWord(OpCodeParameter.Param1);
                            var b = GetVarOrDirectByte(OpCodeParameter.Param2);
                            verb = new MethodInvocation(new MemberAccess(verb, "SetVerbObject")).AddArguments(a, b);
                        }
                        break;
                    case 23:    // Set Back Color
                        {
                            var color = GetVarOrDirectByte(OpCodeParameter.Param1);
                            verb = new MethodInvocation(new MemberAccess(verb, "SetBackColor")).AddArgument(color);
                        }
                        break;
                    default:
                        throw new NotImplementedException(string.Format("VerbOps #{0} is not yet implemented.", _opCode & 0x1F));
                }
            }
            return verb.ToStatement();
        }