示例#1
0
        public override void EnterMethodDecl(GoParser.MethodDeclContext context)
        {
            InFunction           = true;
            OriginalFunctionName = context.IDENTIFIER()?.GetText() ?? "_";
            CurrentFunctionName  = SanitizedIdentifier(OriginalFunctionName);

            GoParser.ParameterDeclContext[] receiverParameters = context.receiver().parameters().parameterDecl();
            string receiverTypeName;

            if (receiverParameters.Length > 0)
            {
                receiverTypeName = receiverParameters[0].type_().GetText();

                // Receiver does not need to handle pointer-to-pointer look ups
                if (receiverTypeName.StartsWith("*"))
                {
                    receiverTypeName = $"ptr<{receiverTypeName.Substring(1)}>";
                }
            }
            else
            {
                receiverTypeName = "object";
            }

            string functionSignature = FunctionSignature.Generate(OriginalFunctionName, new[] { receiverTypeName });

            FunctionInfo currentFunction = null;

            Metadata?.Functions.TryGetValue(functionSignature, out currentFunction);
            CurrentFunction = currentFunction;
        }
示例#2
0
        public override void EnterMethodDecl(GoParser.MethodDeclContext context)
        {
            m_inFunction           = true; // May need to scope certain objects, like consts, to current function
            m_originalFunctionName = context.IDENTIFIER().GetText();
            m_currentFunctionName  = SanitizedIdentifier(m_originalFunctionName);

            // Function signature containing result type and parameters have not been visited yet,
            // so we mark their desired positions and replace once the visit has occurred
            m_functionResultTypeMarker  = string.Format(FunctionResultTypeMarker, m_currentFunctionName);
            m_functionParametersMarker  = string.Format(FunctionParametersMarker, m_currentFunctionName);
            m_functionExecContextMarker = string.Format(FunctionExecContextMarker, m_currentFunctionName);

            m_targetFile.AppendLine($"{Spacing()}{m_functionResultTypeMarker} {m_currentFunctionName}{m_functionParametersMarker}{m_functionExecContextMarker}");
        }
示例#3
0
        public override void EnterMethodDecl(GoParser.MethodDeclContext context)
        {
            m_inFunction           = true; // May need to scope certain objects, like consts, to current function
            m_originalFunctionName = context.IDENTIFIER().GetText();
            m_currentFunctionName  = SanitizedIdentifier(m_originalFunctionName);
            m_variableIdentifiers.Clear();
            m_variableTypes.Clear();

            string receiverTypeName  = context.receiver().parameters().parameterDecl()[0].type_().GetText().Replace("*", "ref ");
            string functionSignature = FunctionSignature.Generate(m_originalFunctionName, new[] { receiverTypeName });

            if (!Metadata.Functions.TryGetValue(functionSignature, out m_currentFunction))
            {
                throw new InvalidOperationException($"Failed to find metadata for method function \"{functionSignature}\".");
            }

            // Function signature containing result type and parameters have not been visited yet,
            // so we mark their desired positions and replace once the visit has occurred
            m_functionResultTypeMarker  = string.Format(FunctionResultTypeMarker, m_currentFunctionName);
            m_functionParametersMarker  = string.Format(FunctionParametersMarker, m_currentFunctionName);
            m_functionExecContextMarker = string.Format(FunctionExecContextMarker, m_currentFunctionName);

            m_targetFile.AppendLine($"{Spacing()}{m_functionResultTypeMarker} {m_currentFunctionName}{m_functionParametersMarker}{m_functionExecContextMarker}");
        }