void IDeclarationNode.PreAnalyze(Analyzer /*!*/ analyzer) { TypeSignatureCompiler.PreAnalyze(node.TypeSignature, analyzer, function); if (function.Version.Next != null) { function.Version.Next.Declaration.Node.PreAnalyze(analyzer); } }
internal override Statement Analyze(FunctionDecl node, Analyzer analyzer) { // functions in incomplete (not emitted) class can't be emitted function.Declaration.IsInsideIncompleteClass = analyzer.IsInsideIncompleteClass(); var attributes = node.Attributes; if (attributes != null) { attributes.Analyze(analyzer, this); } // function is analyzed even if it is unreachable in order to discover more errors at compile-time: function.Declaration.IsUnreachable = analyzer.IsThisCodeUnreachable(); if (function.Declaration.IsUnreachable) { analyzer.ReportUnreachableCode(node.Span); } analyzer.EnterFunctionDeclaration(function); TypeSignatureCompiler.Analyze(node.TypeSignature, analyzer); SignatureCompiler.Analyze(node.Signature, analyzer); function.Validate(analyzer.ErrorSink); node.Body.Analyze(analyzer); // validate function and its body: function.ValidateBody(analyzer.ErrorSink); /* * if (docComment != null) * AnalyzeDocComment(analyzer); */ analyzer.LeaveFunctionDeclaration(); if (function.Declaration.IsUnreachable) { return(EmptyStmt.Unreachable); } else { // add entry point if applicable: analyzer.SetEntryPoint(function, node.Span); return(node); } }
internal override void Emit(FunctionDecl node, CodeGenerator codeGenerator) { Statistics.AST.AddNode("FunctionDecl"); // marks a sequence point if function is declared here (i.e. is m-decl): //Note: this sequence point goes to the function where this function is declared not to this declared function! if (!function.IsLambda && function.Declaration.IsConditional) { codeGenerator.MarkSequencePoint(node.Span); } // emits attributes on the function itself, its return value, type parameters and regular parameters: var attributes = node.Attributes; if (attributes != null) { attributes.Emit(codeGenerator, this); } SignatureCompiler.Emit(node.Signature, codeGenerator); TypeSignatureCompiler.Emit(node.TypeSignature, codeGenerator); // prepares code generator for emitting arg-full overload; // false is returned when the body should not be emitted: if (!codeGenerator.EnterFunctionDeclaration(function)) { return; } // emits the arg-full overload: codeGenerator.EmitArgfullOverloadBody(function, node.Body, node.EntireDeclarationSpan, node.DeclarationBodyPosition); // restores original code generator settings: codeGenerator.LeaveFunctionDeclaration(); // emits function declaration (if needed): // ignore s-decl function declarations except for __autoload; // __autoload function is declared in order to avoid using callbacks when called: if (function.Declaration.IsConditional && !function.QualifiedName.IsAutoloadName) { Debug.Assert(!function.IsLambda); codeGenerator.EmitDeclareFunction(function); } }
void IDeclarationNode.AnalyzeMembers(Analyzer /*!*/ analyzer) { var attributes = node.Attributes; if (attributes != null) { attributes.AnalyzeMembers(analyzer, function.Declaration.Scope); } TypeSignatureCompiler.AnalyzeMembers(node.TypeSignature, analyzer, function.Declaration.Scope); SignatureCompiler.AnalyzeMembers(node.Signature, analyzer, function); // member-analyze the other versions: if (function.Version.Next != null) { function.Version.Next.Declaration.Node.AnalyzeMembers(analyzer); } function.Declaration.Node = null; }