Skip to content

Commit

Permalink
[types] Add type annotation to aid translation.
Browse files Browse the repository at this point in the history
MyPy and mycpp are working!

Fewer compile errors in examples/lexer_main.

Update type checking manifest too.
  • Loading branch information
Andy Chu committed Oct 9, 2019
1 parent 3202763 commit 2460f64
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
7 changes: 5 additions & 2 deletions frontend/reader.py
Expand Up @@ -32,7 +32,8 @@ def GetLine(self):
# type: () -> Tuple[int, Optional[str], int]
line = self._GetLine()
if line is None:
return -1, None, 0
eof_line = None # type: Optional[str]
return -1, eof_line, 0

line_id = self.arena.AddLine(line, self.line_num)
self.line_num += 1
Expand Down Expand Up @@ -113,7 +114,9 @@ def __init__(self, lines, arena):
def GetLine(self):
# type: () -> Tuple[int, Optional[str], int]
if self.pos == self.num_lines:
return -1, None, 0
eof_line = None # type: Optional[str]
return -1, eof_line, 0

line_id, line, start_offset = self.lines[self.pos]

self.pos += 1
Expand Down
3 changes: 3 additions & 0 deletions mycpp/mylib.h
Expand Up @@ -355,13 +355,15 @@ namespace mylib { // MyPy artifact
class File {
public:
virtual void write(Str* s) = 0;
virtual Str* readline() = 0;
};

class Buf : public File {
public:
Buf() : data_(nullptr), len_(0) {
};
virtual void write(Str* s);
virtual Str* readline();
Str* getvalue() { return new Str(data_, len_); }

private:
Expand All @@ -376,6 +378,7 @@ class CFile : public File {
CFile(FILE* f) : f_(f) {
};
virtual void write(Str* s);
virtual Str* readline();

private:
FILE* f_;
Expand Down
1 change: 1 addition & 0 deletions types/osh-parse-manifest.txt
@@ -1,5 +1,6 @@
./asdl/format.py
./asdl/pretty.py
./asdl/pybase.py
./asdl/runtime.py
./bin/osh_parse.py
./core/alloc.py
Expand Down

0 comments on commit 2460f64

Please sign in to comment.