private FinishParameterList ( Signature signature ) : void | ||
signature | Signature | |
return | void |
// Compiles a method signature for a constructor. private static void ConstructorSignature(Compiler c, Signature signature) { c.Consume(TokenType.Name, "Expect constructor name after 'construct'."); // Capture the name. signature = c.SignatureFromToken(signature, SignatureType.Initializer); if (c.Match(TokenType.Eq)) { c.Error("A constructor cannot be a setter."); } if (!c.Match(TokenType.LeftParen)) { c.Error("A constructor cannot be a getter."); return; } if (c.Match(TokenType.RightParen)) return; c.FinishParameterList(signature); c.Consume(TokenType.RightParen, "Expect ')' after parameters."); }
// Compiles a method signature for a subscript operator. private static void SubscriptSignature(Compiler c, Signature signature) { signature.Type = SignatureType.Subscript; // The signature currently has "[" as its name since that was the token that // matched it. Clear that out. signature.Length = 0; signature.Name = ""; // Parse the parameters inside the subscript. c.FinishParameterList(signature); c.Consume(TokenType.RightBracket, "Expect ']' after parameters."); c.MaybeSetter(signature); }
// Compiles a method signature for a constructor. private static void ConstructorSignature(Compiler c, Signature signature) { c.Consume(TokenType.TOKEN_NAME, "Expect constructor name after 'construct'."); // Capture the name. signature = c.SignatureFromToken(SignatureType.SIG_INITIALIZER); if (c.Match(TokenType.TOKEN_EQ)) { c.Error("A constructor cannot be a setter."); } if (!c.Match(TokenType.TOKEN_LEFT_PAREN)) { c.Error("A constructor cannot be a getter."); return; } if (c.Match(TokenType.TOKEN_RIGHT_PAREN)) return; c.FinishParameterList(signature); c.Consume(TokenType.TOKEN_RIGHT_PAREN, "Expect ')' after parameters."); }
// Compiles an (optional) argument list and then calls it. private void MethodCall(Instruction instruction, Signature signature) { Signature called = new Signature { Type = SignatureType.Getter, Arity = 0, Name = signature.Name, Length = signature.Length }; // Parse the argument list, if any. if (Match(TokenType.LeftParen)) { called.Type = SignatureType.Method; // Allow empty an argument list. if (Peek() != TokenType.RightParen) { FinishArgumentList(called); } Consume(TokenType.RightParen, "Expect ')' after arguments."); } // Parse the block argument, if any. if (Match(TokenType.LeftBrace)) { // Include the block argument in the arity. called.Type = SignatureType.Method; called.Arity++; Compiler fnCompiler = new Compiler(_parser, this, true); // Make a dummy signature to track the arity. Signature fnSignature = new Signature { Arity = 0 }; // Parse the parameter list, if any. if (Match(TokenType.Pipe)) { fnCompiler.FinishParameterList(fnSignature); Consume(TokenType.Pipe, "Expect '|' after function parameters."); } fnCompiler._numParams = fnSignature.Arity; fnCompiler.FinishBody(false); String blockName = SignatureToString(called) + " block argument"; fnCompiler.EndCompiler(blockName); } // TODO: Allow Grace-style mixfix methods? // If this is a super() call for an initializer, make sure we got an actual // argument list. if (signature.Type == SignatureType.Initializer) { if (called.Type != SignatureType.Method) { Error("A superclass constructor must have an argument list."); } called.Type = SignatureType.Initializer; } CallSignature(instruction, called); }
// Compiles an (optional) argument list and then calls it. private void MethodCall(Instruction instruction, Signature signature) { Signature called = new Signature { Type = SignatureType.SIG_GETTER, Arity = 0, Name = signature.Name, Length = signature.Length }; // Parse the argument list, if any. if (Match(TokenType.TOKEN_LEFT_PAREN)) { called.Type = SignatureType.SIG_METHOD; // Allow empty an argument list. if (Peek() != TokenType.TOKEN_RIGHT_PAREN) { FinishArgumentList(called); } Consume(TokenType.TOKEN_RIGHT_PAREN, "Expect ')' after arguments."); } // Parse the block argument, if any. if (Match(TokenType.TOKEN_LEFT_BRACE)) { // Include the block argument in the arity. called.Type = SignatureType.SIG_METHOD; called.Arity++; Compiler fnCompiler = new Compiler(parser, this, true); // Make a dummy signature to track the arity. Signature fnSignature = new Signature { Arity = 0 }; // Parse the parameter list, if any. if (Match(TokenType.TOKEN_PIPE)) { fnCompiler.FinishParameterList(fnSignature); Consume(TokenType.TOKEN_PIPE, "Expect '|' after function parameters."); } fnCompiler.numParams = fnSignature.Arity; fnCompiler.FinishBody(false); String blockName = SignatureToString(called) + " block argument"; fnCompiler.EndCompiler(blockName); } // TODO: Allow Grace-style mixfix methods? // If this is a super() call for an initializer, make sure we got an actual // argument list. if (signature.Type == SignatureType.SIG_INITIALIZER) { if (called.Type != SignatureType.SIG_METHOD) { Error("A superclass constructor must have an argument list."); } called.Type = SignatureType.SIG_INITIALIZER; } CallSignature(instruction, called); }