Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
mballance committed Nov 3, 2023
2 parents 3418b09 + d5b107c commit c93fcb6
Show file tree
Hide file tree
Showing 31 changed files with 731 additions and 74 deletions.
5 changes: 5 additions & 0 deletions ast/coretypes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ structs:
init: -1

classes:
- AssocData:
data: []
- Scope:
super: ScopeChild
data:
Expand Down Expand Up @@ -45,6 +47,9 @@ classes:
type: int32_t
is_ctor: false
init: -1
- assocData:
type: UP<AssocData>
is_ctor: false

- ScopeChildRef:
super: ScopeChild
Expand Down
15 changes: 12 additions & 3 deletions ast/expr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,13 @@ classes:
- params: "UP<MethodParameterList>"
- subscript: "UP<Expr>"
- target:
type: int32_t
is_ctor: false
type: UP<SymbolRefPath>
visit: false
# visit: false
# - target:
# is_ctor: false
# type: UP<SymbolRefPath>
# visit: false
- ExprNull:
- super: Expr

Expand All @@ -120,6 +124,11 @@ classes:
- super: Expr
- data:
- target:
# doc: |
# `target` points to the root, or first element, of this
# path. The balance of the reference expression may
# contain further relative references relative to this
# initial base
is_ctor: false
type: UP<SymbolRefPath>
init: 0
Expand Down Expand Up @@ -225,4 +234,4 @@ classes:
- id: UP<ExprId>
- params: UP<TemplateParamValueList>



6 changes: 6 additions & 0 deletions ast/functions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ classes:
is_ctor: False
- proto: UP<FunctionPrototype>
- body: UP<ProceduralStmtSequenceBlock>
- plat: PlatQual
- FunctionParamDecl:
- super: ScopeChild
- data:
Expand All @@ -52,6 +53,11 @@ classes:
- is_pure:
type: bool
is_ctor: false
init: false
- is_target:
type: bool
- is_solve:
type: bool

- FunctionImport:
- super: ScopeChild
Expand Down
3 changes: 2 additions & 1 deletion ast/linking.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ classes:
- type: map<string,int32_t>
- is_ctor: false
- target:
- type: P<Scope>
- type: P<ScopeChild>
- is_ctor: false
- init: 0
- visit: true
Expand Down Expand Up @@ -95,6 +95,7 @@ classes:
- definition:
- type: P<FunctionDefinition>
- is_ctor: false
- init: 0
- plist:
- type: UP<SymbolScope>
- is_ctor: false
Expand Down
2 changes: 1 addition & 1 deletion ivpm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ package:
- name: default
deps:
- name: ciostream
src: pypi
url: https://github.com/mballance-utils/ciostream.git
- name: pyastbuilder
url: https://github.com/mballance/pyastbuilder.git
- name: antlr4-tools.jar
Expand Down
44 changes: 44 additions & 0 deletions python/core.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ cimport zsp_parser.decl as decl
cimport ciostream
from libc.stdint cimport intptr_t
from libcpp.vector cimport vector as std_vector
from libcpp.cast cimport dynamic_cast

cdef Factory _inst = None
cdef class Factory(object):
Expand Down Expand Up @@ -127,6 +128,37 @@ class MarkerSeverityE(IntEnum):
Hint = decl.MarkerSeverityE.Severity_Hint
NumLevels = decl.MarkerSeverityE.Severity_NumLevels

cdef class Location(object):

def __init__(self, file, line, pos):
self._file = file
self._line = line
self._pos = pos

@property
def file(self):
return self._file

cdef class Marker(object):

def __dealloc__(self):
if self._owned:
del self._hndl

cpdef str msg(self):
return self._hndl.msg().decode()

cpdef Location loc(self):
cdef const ast_decl.Location *lp = &self._hndl.loc()
return Location(lp.fileid, lp.lineno, lp.linepos)

@staticmethod
cdef Marker mk(decl.IMarker *hndl, bool owned=True):
ret = Marker()
ret._hndl = hndl
ret._owned = owned
return ret

cdef class MarkerListener(object):
def __dealloc__(self):
if self._owned:
Expand All @@ -139,6 +171,18 @@ cdef class MarkerListener(object):

cdef class MarkerCollector(MarkerListener):

cpdef markers(self):
ret = []
for i in range(self.asCollector().markers().size()):
ret.append(Marker.mk(
self.asCollector().markers().at(i).get(),
False
))
return ret

cdef decl.IMarkerCollector *asCollector(self):
return dynamic_cast[decl.IMarkerCollectorP](self._hndl)

@staticmethod
cdef MarkerCollector mk(decl.IMarkerCollector *hndl, bool owned=True):
ret = MarkerCollector()
Expand Down
20 changes: 20 additions & 0 deletions python/zsp_parser/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

import os

def get_deps():
return []

def get_libs():
return ["zsp-parser"]

def get_libdirs():
pkg_dir = os.path.dirname(os.path.abspath(__file__))
return [pkg_dir]

def get_incdirs():
pkg_dir = os.path.dirname(os.path.abspath(__file__))
if os.path.isdir(os.path.join(pkg_dir, "include")):
return [os.path.join(pkg_dir, "include")]
else:
root_dir = os.path.abspath(os.path.join(pkg_dir, "../.."))
return [os.path.join(root_dir, "src", "include")]
20 changes: 20 additions & 0 deletions python/zsp_parser/core.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ cimport zsp_parser.decl as decl
cimport debug_mgr.core as dm_core
cimport zsp_parser.ast as ast
cimport ciostream
from libc.stdint cimport int32_t
from libcpp cimport bool

cdef class Factory(object):
Expand Down Expand Up @@ -53,6 +54,21 @@ cdef class Linker(object):
@staticmethod
cdef Linker mk(decl.ILinker *hndl, bool owned=*)

cdef class Location(object):
cdef int32_t _file
cdef int32_t _line
cdef int32_t _pos

cdef class Marker(object):
cdef decl.IMarker *_hndl
cdef bool _owned

cpdef str msg(self)

cpdef Location loc(self)

@staticmethod
cdef Marker mk(decl.IMarker *hndl, bool owned=*)

cdef class MarkerListener(object):
cdef decl.IMarkerListener *_hndl
Expand All @@ -62,6 +78,10 @@ cdef class MarkerListener(object):

cdef class MarkerCollector(MarkerListener):

cpdef markers(self)

cdef decl.IMarkerCollector *asCollector(self)

@staticmethod
cdef MarkerCollector mk(decl.IMarkerCollector *hndl, bool owned=*)

Expand Down
12 changes: 5 additions & 7 deletions python/zsp_parser/decl.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ from zsp_parser cimport ast_decl as ast
cimport ciostream

ctypedef IFactory *IFactoryP
ctypedef IMarker *IMarkerP
ctypedef IMarkerCollector *IMarkerCollectorP
ctypedef unique_ptr[IMarker] IMarkerUP


cdef extern from "zsp/parser/IFactory.h" namespace "zsp::parser":
Expand Down Expand Up @@ -66,15 +69,10 @@ cdef extern from "zsp/parser/IMarker.h" namespace "zsp::parser":
Severity_Hint "zsp::parser::MarkerSeverityE::Hint"
Severity_NumLevels "zsp::parser::MarkerSeverityE::NumLevels"

cdef cppclass Location:
int32_t file;
int32_t line;
int32_t pos;

cdef cppclass IMarker:
const cpp_string &msg() const
MarkerSeverityE severity() const
const Location &loc() const;
const ast.Location &loc() const;
IMarker *clone() const

cdef extern from "zsp/parser/IMarkerListener.h" namespace "zsp::parser":
Expand All @@ -84,7 +82,7 @@ cdef extern from "zsp/parser/IMarkerListener.h" namespace "zsp::parser":

cdef extern from "zsp/parser/IMarkerCollector.h" namespace "zsp::parser":
cdef cppclass IMarkerCollector(IMarkerListener):
pass
const cpp_vector[IMarkerUP] &markers() const

cdef extern from "zsp/parser/ISymbolTableIterator.h" namespace "zsp::parser":
cdef cppclass ISymbolTableIterator:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
sys.argv.remove("-DDEBUG")
CMAKE_BUILD_TYPE="Debug"
_DEBUG = True
elif "DEBUG" in os.environ.keys() and os.environ["DEBUG"] != "":
elif "DEBUG" in os.environ.keys() and os.environ["DEBUG"]:
CMAKE_BUILD_TYPE="Debug"
_DEBUG = True
else:
Expand Down
2 changes: 1 addition & 1 deletion src/.antlr/PSSLexer.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated from /project/fun/zuspec/zuspec-parser/src/PSSLexer.g4 by ANTLR 4.9.2
// Generated from /project/fun/zuspec/zuspec-fe-parser/packages/zuspec-parser/src/PSSLexer.g4 by ANTLR 4.9.2
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.Token;
Expand Down
Loading

0 comments on commit c93fcb6

Please sign in to comment.