| 684 | } |
| 685 | |
| 686 | AstNode *SymbolScanner::handleStruct(AstNode *node, top_down) |
| 687 | { |
| 688 | AstNode *structNameNode = (*node)[0]; |
| 689 | if (!structNameNode && m_currentAlias == nullptr) |
| 690 | { |
| 691 | throw semantic_error(format_string("line %d: illegal anonymous struct definition at file level", |
| 692 | node->getToken().getFirstLine())); |
| 693 | } |
| 694 | |
| 695 | // Create the struct symbol. |
| 696 | StructType *newStruct; |
| 697 | if (structNameNode) |
| 698 | { |
| 699 | const Token &tok = structNameNode->getToken(); |
| 700 | string name = tok.getStringValue(); |
| 701 | Log::debug("struct: %s\n", name.c_str()); |
| 702 | |
| 703 | /* match forward declaration with definition */ |
| 704 | auto forwardDecl = m_forwardDeclarations.find(name); |
| 705 | if (forwardDecl != m_forwardDeclarations.end()) |
| 706 | { |
| 707 | newStruct = dynamic_cast<StructType *>(forwardDecl->second); |
| 708 | if (newStruct != nullptr) |
| 709 | { |
| 710 | new (newStruct) StructType(tok); |
| 711 | } |
| 712 | else |
| 713 | { |
| 714 | throw syntax_error( |
| 715 | format_string("line %d: Structure definition type name didn't match data type of " |
| 716 | "forward declaration from line %d.", |
| 717 | tok.getFirstLine(), forwardDecl->second->getFirstLine())); |
| 718 | } |
| 719 | } |
| 720 | else |
| 721 | { |
| 722 | newStruct = new StructType(tok); |
| 723 | } |
| 724 | } |
| 725 | else |
| 726 | { |
| 727 | Log::debug( |
| 728 | "typedef struct: %s\n", |
| 729 | check_null(check_null(check_null(node->getParent())->getChild(0))->getTokenValue())->toString().c_str()); |
| 730 | newStruct = new StructType(""); |
| 731 | } |
| 732 | |
| 733 | m_currentStruct = newStruct; |
| 734 | |
| 735 | return nullptr; |
| 736 | } |
| 737 | |
| 738 | AstNode *SymbolScanner::handleStruct(AstNode *node, bottom_up) |
| 739 | { |
nothing calls this directly
no test coverage detected