Beispiel #1
0
        public void MethodReferenceTest()
        {
            CallElement target = new CallElement();

            string val = null; // TODO: Assign to an appropriate value for the property

            target.MethodReference = val;


            Assert.AreEqual(val, target.MethodReference, "Composestar.StarLight.Entities.LanguageModel.CallElement.MethodReference was not " +
                            "set correctly.");
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
Beispiel #2
0
        private void ParseVariableCall(string line, Variable variable)
        {
            ++currentIndex;

            var callElement = new CallElement();

            currentIndex = ParserHelper.ReadWord(line, currentIndex, out callElement.VariableName);

            if (string.IsNullOrEmpty(callElement.VariableName))
            {
                throw new CompilationException($"Invalid variable name at {currentLine}:{currentIndex}");
            }

            variable.Elements.Add(callElement);
        }
        public void Parse(string data, ref TemplateElementContainer parent)
        {
            var regex = @"call\(\s*(?<property>.*)\s*\)";

            var match = Regex.Match(data, regex);

            if (!match.Success)
            {
                throw new InvalidOperationException($"Unable to parse call epxression: {data}");
            }

            var newCall = new CallElement(parent)
            {
                TypeReference = match.Groups["property"].Value
            };

            parent.Children.Add(newCall);
        }
Beispiel #4
0
        public override void VisitMethodDefinition(MethodDefinition method)
        {
            // If we only extract the unresolvedtypes then we most likely are only interested
            // in methods which can be overriden. So skip the rest.
            if (ExtractUnresolvedOnly && !method.IsVirtual)
            {
                return;
            }

            // Create a new method element
            MethodElement me = new MethodElement();

            me.Name          = method.Name;
            me.ReturnType    = method.ReturnType.ReturnType.FullName;
            me.IsAbstract    = method.IsAbstract;
            me.IsConstructor = method.IsConstructor;
            me.IsStatic      = method.IsStatic;
            me.IsVirtual     = method.IsVirtual;

            MethodAttributes memberAccess = method.Attributes & MethodAttributes.MemberAccessMask;

            me.IsPrivate = memberAccess == MethodAttributes.Private;
            me.IsPublic  = memberAccess == MethodAttributes.Public;

            // Add the parameters
            foreach (ParameterDefinition param in method.Parameters)
            {
                ParameterElement pe = new ParameterElement();

                pe.Name    = param.Name;
                pe.Ordinal = (short)(param.Sequence);
                pe.Type    = param.ParameterType.FullName;

                if ((param.Attributes & Mono.Cecil.ParameterAttributes.Out) != Mono.Cecil.ParameterAttributes.Out)
                {
                    pe.ParameterOption |= ParameterOptions.In;
                }
                else
                {
                    pe.ParameterOption &= ~ParameterOptions.In;
                }

                if ((param.Attributes & Mono.Cecil.ParameterAttributes.Out) == Mono.Cecil.ParameterAttributes.Out)
                {
                    pe.ParameterOption |= ParameterOptions.Out;
                }

                if ((param.Attributes & Mono.Cecil.ParameterAttributes.Optional) == Mono.Cecil.ParameterAttributes.Optional)
                {
                    pe.ParameterOption |= ParameterOptions.Optional;
                }

                // Remark; we do not harvest custom attributes here.

                me.Parameters.Add(pe);
            }

            // Add the method body
            if (ProcessMethodBody && method.HasBody)
            {
                me.Body = new Entities.LanguageModel.MethodBody();

                List <string> callList = new List <string>();

                foreach (Instruction instr in method.Body.Instructions)
                {
                    if (instr.OpCode.Value == OpCodes.Call.Value ||
                        instr.OpCode.Value == OpCodes.Calli.Value ||
                        instr.OpCode.Value == OpCodes.Callvirt.Value
                        )
                    {
                        CallElement ce = new CallElement();

                        // instr.Operand can be a MethodReference or a CallSite
                        ce.MethodReference = instr.Operand.ToString();

                        if (!callList.Contains(ce.MethodReference))
                        {
                            me.Body.Calls.Add(ce);
                            callList.Add(ce.MethodReference);
                        }
                    }
                }
            }

            // Custom attributes
            me.Attributes.AddRange(ExtractCustomAttributes(method.CustomAttributes));

            // Set the signature
            string declaringTypeName = method.DeclaringType.FullName;

            me.Signature = MethodElement.GenerateSignature(declaringTypeName, me);

            // Add to the type
            _currentType.Methods.Add(me);
        }