xref: /Universal-ctags/parsers/cxx/cxx_subparser.c (revision 6fcf84e3f3837d72b189ec0592d656afb6dcf004)
1 /*
2 *   Copyright (c) 2017, Red Hat, Inc.
3 *   Copyright (c) 2017, Masatake YAMATO
4 *
5 *   This source code is released for free distribution under the terms of the
6 *   GNU General Public License version 2 or (at your option) any later version.
7 *
8 *   This module contains functions for parsing and scanning C++ source files
9 */
10 
11 #include "general.h"
12 
13 #include "cxx_subparser_internal.h"
14 #include "cxx_token_chain.h"
15 
16 
cxxSubparserNotifyParseAccessSpecifier(ptrArray * pSubparsers)17 bool cxxSubparserNotifyParseAccessSpecifier (ptrArray *pSubparsers)
18 {
19 	bool bR = false;
20 	subparser *pSubparser;
21 
22 	foreachSubparser (pSubparser, false)
23 	{
24 		cxxSubparser *pS = (cxxSubparser *)pSubparser;
25 		if (pS->parseAccessSpecifierNotify)
26 		{
27 			enterSubparser(pSubparser);
28 			if (pS->parseAccessSpecifierNotify (pS))
29 			{
30 				ptrArrayAdd(pSubparsers, pS);
31 				bR = true;
32 			}
33 			leaveSubparser();
34 		}
35 	}
36 	return bR;
37 }
38 
cxxSubparserNotifyfoundExtraIdentifierAsAccessSpecifier(ptrArray * pSubparsers,CXXToken * pToken)39 void cxxSubparserNotifyfoundExtraIdentifierAsAccessSpecifier(ptrArray *pSubparsers,
40 															 CXXToken *pToken)
41 {
42 	unsigned int c = ptrArrayCount(pSubparsers);
43 	for (unsigned int i = 0; i < c; i++)
44 	{
45 		cxxSubparser *pS = ptrArrayItem (pSubparsers, i);
46 		if (pS->foundExtraIdentifierAsAccessSpecifier)
47 		{
48 			enterSubparser((subparser*)pS);
49 			pS->foundExtraIdentifierAsAccessSpecifier(pS, pToken);
50 			leaveSubparser();
51 		}
52 	}
53 }
54 
cxxSubparserNewIdentifierAsHeadOfMemberNotify(CXXToken * pToken)55 bool cxxSubparserNewIdentifierAsHeadOfMemberNotify(CXXToken *pToken)
56 {
57 	subparser *pSubparser;
58 	bool handled = false;
59 
60 	foreachSubparser (pSubparser, false)
61 	{
62 		cxxSubparser *pS = (cxxSubparser *)pSubparser;
63 		if (pS->newIdentifierAsHeadOfMemberNotify)
64 		{
65 			enterSubparser(pSubparser);
66 			if (pS->newIdentifierAsHeadOfMemberNotify (pS, pToken))
67 				handled = true;
68 			leaveSubparser();
69 			if (handled)
70 				break;
71 		}
72 	}
73 	return handled;
74 }
75 
cxxSubparserUnknownIdentifierInClassNotify(CXXToken * pToken)76 void cxxSubparserUnknownIdentifierInClassNotify(CXXToken *pToken)
77 {
78 	subparser *pSubparser;
79 	bool handled = false;
80 
81 	foreachSubparser (pSubparser, false)
82 	{
83 		cxxSubparser *pS = (cxxSubparser *)pSubparser;
84 		if (pS->unknownIdentifierInClassNotify)
85 		{
86 			enterSubparser(pSubparser);
87 			if (pS->unknownIdentifierInClassNotify (pS, pToken))
88 				handled = true;
89 			leaveSubparser();
90 			if (handled)
91 				break;
92 		}
93 
94 	}
95 }
96 
cxxSubparserNotifyEnterBlock(void)97 void cxxSubparserNotifyEnterBlock (void)
98 {
99 	subparser *pSubparser;
100 	foreachSubparser (pSubparser, false)
101 	{
102 		cxxSubparser *pS = (cxxSubparser *)pSubparser;
103 		if (pS->enterBlockNotify)
104 		{
105 			enterSubparser(pSubparser);
106 			pS->enterBlockNotify (pS);
107 			leaveSubparser();
108 		}
109 	}
110 }
111 
cxxSubparserNotifyLeaveBlock(void)112 void cxxSubparserNotifyLeaveBlock (void)
113 {
114 	subparser *pSubparser;
115 	foreachSubparser (pSubparser, false)
116 	{
117 		cxxSubparser *pS = (cxxSubparser *)pSubparser;
118 		if (pS->leaveBlockNotify)
119 		{
120 			enterSubparser(pSubparser);
121 			pS->leaveBlockNotify (pS);
122 			leaveSubparser();
123 		}
124 	}
125 }
126