TODO(tfoley): this definition is now largely redundant (only used to parse requirements for import operators)
| 1254 | // TODO(tfoley): this definition is now largely redundant (only |
| 1255 | // used to parse requirements for import operators) |
| 1256 | RefPtr<FunctionSyntaxNode> Parser::ParseFunction(bool parseBody) |
| 1257 | { |
| 1258 | anonymousParamCounter = 0; |
| 1259 | RefPtr<FunctionSyntaxNode> function = new FunctionSyntaxNode(); |
| 1260 | function->modifiers = ParseModifiers(this); |
| 1261 | |
| 1262 | PushScope(function.Ptr()); |
| 1263 | function->ReturnTypeNode = ParseType(); |
| 1264 | FillPosition(function.Ptr()); |
| 1265 | Token name; |
| 1266 | if (LookAheadToken("operator")) |
| 1267 | { |
| 1268 | ReadToken(); |
| 1269 | name = ReadToken(); |
| 1270 | switch (name.Type) |
| 1271 | { |
| 1272 | case TokenType::OpAdd: case TokenType::OpSub: case TokenType::OpMul: case TokenType::OpDiv: |
| 1273 | case TokenType::OpMod: case TokenType::OpNot: case TokenType::OpBitNot: case TokenType::OpLsh: case TokenType::OpRsh: |
| 1274 | case TokenType::OpEql: case TokenType::OpNeq: case TokenType::OpGreater: case TokenType::OpLess: case TokenType::OpGeq: |
| 1275 | case TokenType::OpLeq: case TokenType::OpAnd: case TokenType::OpOr: case TokenType::OpBitXor: case TokenType::OpBitAnd: |
| 1276 | case TokenType::OpBitOr: case TokenType::OpInc: case TokenType::OpDec: |
| 1277 | break; |
| 1278 | default: |
| 1279 | sink->diagnose(name.Position, Diagnostics::invalidOperator, name.Content); |
| 1280 | break; |
| 1281 | } |
| 1282 | } |
| 1283 | else |
| 1284 | { |
| 1285 | name = ReadToken(TokenType::Identifier); |
| 1286 | } |
| 1287 | function->Name = name; |
| 1288 | ReadToken(TokenType::LParent); |
| 1289 | while(!AdvanceIfMatch(this, TokenType::RParent)) |
| 1290 | { |
| 1291 | function->Members.Add(ParseParameter()); |
| 1292 | if (AdvanceIf(this, TokenType::RParent)) |
| 1293 | break; |
| 1294 | ReadToken(TokenType::Comma); |
| 1295 | } |
| 1296 | if (parseBody) |
| 1297 | { |
| 1298 | if (!function->IsExtern()) |
| 1299 | function->Body = ParseBlockStatement(); |
| 1300 | else |
| 1301 | ReadToken(TokenType::Semicolon); |
| 1302 | } |
| 1303 | PopScope(); |
| 1304 | return function; |
| 1305 | } |
| 1306 | |
| 1307 | RefPtr<StructSyntaxNode> Parser::ParseStruct() |
| 1308 | { |
nothing calls this directly
no test coverage detected