# error handling import os import atexit import tempfile import inspect import re import weakref from collections import * from pyrser import meta Severity = meta.enum('INFO', 'WARNING', 'ERROR') class LocationInfo: def __init__(self, filepath: str, line: int, col: int, size: int=1): self.filepath = filepath self.line = line self.col = col self.size = size @staticmethod def from_stream(stream: 'Stream', is_error=False) -> 'LocationInfo': if stream._name is None and is_error is True: (fh, stream._name) = tempfile.mkstemp() tmpf = os.fdopen(fh, 'w') tmpf.write(stream._content) tmpf.close() atexit.register(os.remove, stream._name) loc = LocationInfo( stream._name,
from pyrser import parsing, meta Storages = meta.enum('AUTO', 'REGISTER', 'TYPEDEF', 'STATIC', 'EXTERN', 'INLINE', 'VIRTUAL', 'EXPLICIT', 'FORCEINLINE', 'THREAD') Qualifiers = meta.enum('AUTO', 'CONST', 'VOLATILE', 'RESTRICT', 'W64', 'STDCALL', 'CDECL', 'PTR32', 'PTR64', 'FASTCALL') Specifiers = meta.enum('AUTO', 'STRUCT', 'UNION', 'ENUM', 'LONG', 'LONGLONG', 'SHORT') Signs = meta.enum('AUTO', 'SIGNED', 'UNSIGNED') # EXPRESSION PART class Expr(parsing.Node): """All expression""" class Func(Expr): """For almost everything""" def __init__(self, call_expr: Expr, params: list): Expr.__init__(self) self.call_expr = call_expr self.params = params class BlockInit(Expr): """Initializer Block Expression"""
from pyrser import parsing, meta Storages = meta.enum('AUTO', 'REGISTER', 'TYPEDEF', 'STATIC', 'EXTERN', 'INLINE', 'VIRTUAL', 'EXPLICIT', 'FORCEINLINE', 'THREAD') Qualifiers = meta.enum('AUTO', 'CONST', 'VOLATILE', 'RESTRICT', 'W64', 'STDCALL', 'CDECL', 'PTR32', 'PTR64', 'FASTCALL') Specifiers = meta.enum('AUTO', 'STRUCT', 'UNION', 'ENUM', 'LONG', 'LONGLONG', 'SHORT') Signs = meta.enum('AUTO', 'SIGNED', 'UNSIGNED') # EXPRESSION PART class Expr(parsing.Node): """All expression""" class Func(Expr): """For almost everything""" def __init__(self, call_expr: Expr, params: list): Expr.__init__(self) self.call_expr = call_expr self.params = params class BlockInit(Expr): """Initializer Block Expression""" def __init__(self, body: [Expr]): self.body = body
# scope for type checking import weakref from collections import * from pyrser import fmt, meta from pyrser.type_system.symbol import * from pyrser.type_system.signature import * from pyrser.type_system.evalctx import * from pyrser.type_system.translator import * from pyrser.parsing.node import * from pyrser.passes.to_yml import * StateScope = meta.enum('FREE', 'LINKED', 'EMBEDDED') # forward just for annotation (not the same id that final type) class Scope: pass class Scope(Symbol): """ Scope of Signature for a Scope/namespace/type etc... Basic abstraction of type checking. Scope is not a 'pure' python set but something between a set and a dict... """ def __init__(self, name: str=None, sig: [Signature]=None, state=StateScope.FREE, is_namespace=True): """Unnamed scope for global scope A Scope have basically 3 possibles states: