-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added objc generator with basic methods implemented
- Loading branch information
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env python | ||
|
||
from ddp_generator import DDPGenerator, to_camel_case | ||
import jsbeautifier | ||
import os | ||
from subprocess import Popen, PIPE, STDOUT | ||
|
||
UNCRUSTIFY_ROOT_DIR = "{}{}..{}..{}thirdparty{}uncrustify".format(os.path.dirname(os.path.realpath(__file__)), | ||
os.path.sep, | ||
os.path.sep, | ||
os.path.sep, | ||
os.path.sep) | ||
UNCRUSTIFY_PATH = "{}{}src{}uncrustify".format(UNCRUSTIFY_ROOT_DIR, os.path.sep, os.path.sep) | ||
UNCRUSTIFY_CFG = "{}{}configs{}objc.cfg".format(UNCRUSTIFY_ROOT_DIR, os.path.sep, os.path.sep) | ||
|
||
class ObjectiveCGenerator(DDPGenerator): | ||
|
||
def class_prefix(self): | ||
return "DDP" | ||
|
||
def language(self): | ||
return "objc" | ||
|
||
def beautify(self, code): | ||
if not os.path.isfile(UNCRUSTIFY_PATH): | ||
raise "Cannot beautify Objective-C code without uncrustify, which can be built via setup.sh" | ||
|
||
pipe = Popen([UNCRUSTIFY_PATH, "-c", "{}".format(UNCRUSTIFY_CFG)], | ||
stdout=PIPE, stdin=PIPE, stderr=STDOUT) | ||
output = pipe.communicate(input="{}\n".format(code))[0] | ||
return output.decode() | ||
|
||
def recase(self, variable): | ||
return to_camel_case(variable) | ||
|
||
def api_header_name(self, service): | ||
return "{}{}.h".format(self.class_prefix(), service.name) | ||
|
||
def api_source_name(self, service): | ||
return None#"{}{}.m".format(self.class_prefix(), service.name) | ||
|
||
def simulator_header_name(self, services): | ||
return None | ||
|
||
def simulator_source_name(self, services): | ||
return None | ||
|
||
def examples_source_name(self, method_name): | ||
return None | ||
#return "{}Example.{}.m".format(self.class_prefix(), method_name) | ||
|
||
def tests_source_name(self, method_name): | ||
return None | ||
#return "{}Test.{}.m".format(self.class_prefix(), method_name) | ||
|
||
if __name__ == '__main__': | ||
ObjectiveCGenerator().run() |