2015-09-29 13:11:25 +03:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
2018-03-15 11:31:17 +03:00
|
|
|
wakatime.dependencies.c_cpp
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2015-09-29 13:11:25 +03:00
|
|
|
|
|
|
|
Parse dependencies from C++ code.
|
|
|
|
|
|
|
|
:copyright: (c) 2014 Alan Hamlett.
|
|
|
|
:license: BSD, see LICENSE for more details.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from . import TokenParser
|
|
|
|
|
|
|
|
|
2016-06-13 17:48:53 +03:00
|
|
|
class CParser(TokenParser):
|
2015-09-29 13:11:25 +03:00
|
|
|
exclude = [
|
|
|
|
r'^stdio\.h$',
|
|
|
|
r'^stdlib\.h$',
|
|
|
|
r'^string\.h$',
|
|
|
|
r'^time\.h$',
|
|
|
|
]
|
2016-06-13 17:48:53 +03:00
|
|
|
state = None
|
2015-09-29 13:11:25 +03:00
|
|
|
|
|
|
|
def parse(self):
|
|
|
|
for index, token, content in self.tokens:
|
|
|
|
self._process_token(token, content)
|
|
|
|
return self.dependencies
|
|
|
|
|
|
|
|
def _process_token(self, token, content):
|
2016-06-13 17:48:53 +03:00
|
|
|
if self.partial(token) == 'Preproc' or self.partial(token) == 'PreprocFile':
|
2015-09-29 13:11:25 +03:00
|
|
|
self._process_preproc(token, content)
|
|
|
|
else:
|
|
|
|
self._process_other(token, content)
|
|
|
|
|
|
|
|
def _process_preproc(self, token, content):
|
2016-06-13 17:48:53 +03:00
|
|
|
if self.state == 'include':
|
|
|
|
if content != '\n' and content != '#':
|
|
|
|
content = content.strip().strip('"').strip('<').strip('>').strip()
|
|
|
|
self.append(content, truncate=True, separator='/')
|
|
|
|
self.state = None
|
|
|
|
elif content.strip().startswith('include'):
|
|
|
|
self.state = 'include'
|
|
|
|
else:
|
|
|
|
self.state = None
|
2015-09-29 13:11:25 +03:00
|
|
|
|
|
|
|
def _process_other(self, token, content):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2016-06-13 17:48:53 +03:00
|
|
|
class CppParser(CParser):
|
|
|
|
pass
|