| ... | @@ -713,6 +713,30 @@ static void render_aliases(Context *c) { | ... | @@ -713,6 +713,30 @@ static void render_aliases(Context *c) { |
| 713 | } | 713 | } |
| 714 | } | 714 | } |
| 715 | | 715 | |
| | 716 | static void process_preprocessor_entities(Context *c, ASTUnit &unit) { |
| | 717 | for (PreprocessedEntity *entity : unit.getLocalPreprocessingEntities()) { |
| | 718 | switch (entity->getKind()) { |
| | 719 | case PreprocessedEntity::InvalidKind: |
| | 720 | case PreprocessedEntity::InclusionDirectiveKind: |
| | 721 | case PreprocessedEntity::MacroExpansionKind: |
| | 722 | continue; |
| | 723 | case PreprocessedEntity::MacroDefinitionKind: |
| | 724 | { |
| | 725 | MacroDefinitionRecord *macro = static_cast<MacroDefinitionRecord *>(entity); |
| | 726 | const char *name = macro->getName()->getNameStart(); |
| | 727 | fprintf(stderr, "definition macro: %s\n", name); |
| | 728 | SourceRange range = macro->getSourceRange(); |
| | 729 | SourceLocation begin_loc = range.getBegin(); |
| | 730 | SourceLocation end_loc = range.getEnd(); |
| | 731 | |
| | 732 | const char *start_c = c->source_manager->getCharacterData(begin_loc); |
| | 733 | const char *end_c = c->source_manager->getCharacterData(end_loc); |
| | 734 | fprintf(stderr, "source: '%.*s'\n", (int)(end_c - start_c), start_c); |
| | 735 | } |
| | 736 | } |
| | 737 | } |
| | 738 | } |
| | 739 | |
| 716 | int parse_h_buf(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, Buf *source, | 740 | int parse_h_buf(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, Buf *source, |
| 717 | const char **args, int args_len, const char *libc_include_path, bool warnings_on) | 741 | const char **args, int args_len, const char *libc_include_path, bool warnings_on) |
| 718 | { | 742 | { |
| ... | @@ -774,6 +798,12 @@ int parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, | ... | @@ -774,6 +798,12 @@ int parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, |
| 774 | | 798 | |
| 775 | // we don't need spell checking and it slows things down | 799 | // we don't need spell checking and it slows things down |
| 776 | clang_argv->append("-fno-spell-checking"); | 800 | clang_argv->append("-fno-spell-checking"); |
| | 801 | |
| | 802 | // this gives us access to preprocessing entities, presumably at |
| | 803 | // the cost of performance |
| | 804 | clang_argv->append("-Xclang"); |
| | 805 | clang_argv->append("-detailed-preprocessing-record"); |
| | 806 | |
| 777 | // to make the end argument work | 807 | // to make the end argument work |
| 778 | clang_argv->append(nullptr); | 808 | clang_argv->append(nullptr); |
| 779 | | 809 | |
| ... | @@ -844,6 +874,8 @@ int parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, | ... | @@ -844,6 +874,8 @@ int parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, |
| 844 | c->root = create_node(c, NodeTypeRoot); | 874 | c->root = create_node(c, NodeTypeRoot); |
| 845 | ast_unit->visitLocalTopLevelDecls(c, decl_visitor); | 875 | ast_unit->visitLocalTopLevelDecls(c, decl_visitor); |
| 846 | | 876 | |
| | 877 | process_preprocessor_entities(c, *ast_unit); |
| | 878 | |
| 847 | render_aliases(c); | 879 | render_aliases(c); |
| 848 | | 880 | |
| 849 | normalize_parent_ptrs(c->root); | 881 | normalize_parent_ptrs(c->root); |