Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stage2 translate-c: function body statements #2569

Merged
merged 38 commits into from Jul 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
fceedad
WIP translate var decl
hryx May 26, 2019
99f0b28
var decl: mut_token, create child scope
hryx May 26, 2019
c79b8ae
var decl: threadlocal
hryx May 27, 2019
1a8f8c6
var decl: init node
hryx May 27, 2019
9c437f9
var decl: ImplicitCastExpr
hryx May 27, 2019
3bbee1b
expr: BitCast for ImplicitCastExpr
hryx May 27, 2019
2aa1c5d
Remove unused local struct type
hryx May 27, 2019
e1f3eec
Merge branch 'master' into translate-c-userland
hryx May 28, 2019
2229986
Prevent infinite recursion
hryx May 28, 2019
e07888e
expr: FunctionToPointerDecay & ArrayToPointerDecay for ImplicitCastExpr
hryx May 28, 2019
b558d09
expr: DeclRefExpr
hryx May 28, 2019
e632c2a
(broken) port a bunch of stuff from stage1 translate-c
hryx May 28, 2019
3e14f86
Implement missing clang functions from last commit
hryx May 29, 2019
1f82c7b
transCStyleCastExpr
hryx Jun 8, 2019
1692a76
transImplictCastExpr: LValueToRValue
hryx Jun 8, 2019
ed5b833
(broken) translate Paren type
hryx Jun 8, 2019
ad0f056
Merge branch 'master' into translate-c-userland
hryx Jun 8, 2019
586c36d
Restore fn decls removed during conflict
hryx Jun 9, 2019
84e479d
(broken) local var decls, integer literals (part)
hryx Jun 10, 2019
0f545e5
transReturnStmt
hryx Jun 11, 2019
6325ffc
Assign undefined literal (instead of null) when no init value
hryx Jun 23, 2019
4ae95d7
Translate assignment BinaryOperator statements
hryx Jun 23, 2019
4c8b460
Fix recursive self-referential block
hryx Jun 23, 2019
1c86a19
Fix order of tokens; omit 'pub' for fn types
hryx Jun 23, 2019
c423697
Merge branch 'master' into translate-c-userland
hryx Jun 23, 2019
226a23d
stage1: always render space after `fn` like stage2
hryx Jun 23, 2019
b2e06c3
Observe translate mode in stage2
hryx Jun 23, 2019
69b90e0
transStringLiteral
hryx Jun 23, 2019
f845994
transBinaryOperator: Add, Sub
hryx Jun 24, 2019
8435351
Escape C string literals
hryx Jun 25, 2019
b4bd52c
Create and render big.Int from IntegerLiteral; group BinaryOperator
hryx Jun 28, 2019
3e0ff32
Separate with space instead of LF to prevent rendering excessive inde…
hryx Jun 28, 2019
2060c7c
Merge branch 'master' into translate-c-userland
hryx Jun 28, 2019
6462688
Use new width format option
hryx Jun 28, 2019
cc74bf5
Translate IntegralCast; add stage2 test coverage
hryx Jun 28, 2019
102bf52
Fix string literal: not null-terminated (thanks @mikdusan)
hryx Jun 29, 2019
247e567
Don't return a slice pointing to a deceased stack address
hryx Jun 29, 2019
0e38f72
Define different struct size for APValue on Windows (thanks @Sahnvour)
hryx Jun 29, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
79 changes: 78 additions & 1 deletion src-self-hosted/clang.zig
@@ -1,4 +1,5 @@
pub const struct_ZigClangAPValue = @OpaqueType();
const builtin = @import("builtin");

pub const struct_ZigClangAPSInt = @OpaqueType();
pub const struct_ZigClangAPFloat = @OpaqueType();
pub const struct_ZigClangASTContext = @OpaqueType();
Expand Down Expand Up @@ -723,13 +724,15 @@ pub extern fn ZigClangSourceLocation_eq(a: struct_ZigClangSourceLocation, b: str
pub extern fn ZigClangTypedefType_getDecl(self: ?*const struct_ZigClangTypedefType) ?*const struct_ZigClangTypedefNameDecl;
pub extern fn ZigClangTypedefNameDecl_getUnderlyingType(self: ?*const struct_ZigClangTypedefNameDecl) struct_ZigClangQualType;
pub extern fn ZigClangQualType_getCanonicalType(self: struct_ZigClangQualType) struct_ZigClangQualType;
pub extern fn ZigClangQualType_getTypeClass(self: struct_ZigClangQualType) ZigClangTypeClass;
pub extern fn ZigClangQualType_getTypePtr(self: struct_ZigClangQualType) *const struct_ZigClangType;
pub extern fn ZigClangQualType_addConst(self: [*c]struct_ZigClangQualType) void;
pub extern fn ZigClangQualType_eq(self: struct_ZigClangQualType, arg1: struct_ZigClangQualType) bool;
pub extern fn ZigClangQualType_isConstQualified(self: struct_ZigClangQualType) bool;
pub extern fn ZigClangQualType_isVolatileQualified(self: struct_ZigClangQualType) bool;
pub extern fn ZigClangQualType_isRestrictQualified(self: struct_ZigClangQualType) bool;
pub extern fn ZigClangType_getTypeClass(self: ?*const struct_ZigClangType) ZigClangTypeClass;
pub extern fn ZigClangType_getPointeeType(self: ?*const struct_ZigClangType) struct_ZigClangQualType;
pub extern fn ZigClangType_isVoidType(self: ?*const struct_ZigClangType) bool;
pub extern fn ZigClangType_getTypeClassName(self: *const struct_ZigClangType) [*]const u8;
pub extern fn ZigClangStmt_getBeginLoc(self: *const struct_ZigClangStmt) struct_ZigClangSourceLocation;
Expand Down Expand Up @@ -894,3 +897,77 @@ pub const ZigClangCompoundStmt_const_body_iterator = [*c]const *struct_ZigClangS

pub extern fn ZigClangCompoundStmt_body_begin(self: *const ZigClangCompoundStmt) ZigClangCompoundStmt_const_body_iterator;
pub extern fn ZigClangCompoundStmt_body_end(self: *const ZigClangCompoundStmt) ZigClangCompoundStmt_const_body_iterator;

pub const ZigClangDeclStmt_const_decl_iterator = [*c]const *struct_ZigClangDecl;

pub extern fn ZigClangDeclStmt_decl_begin(self: *const ZigClangDeclStmt) ZigClangDeclStmt_const_decl_iterator;
pub extern fn ZigClangDeclStmt_decl_end(self: *const ZigClangDeclStmt) ZigClangDeclStmt_const_decl_iterator;

pub extern fn ZigClangVarDecl_getType(self: ?*const struct_ZigClangVarDecl) struct_ZigClangQualType;
pub extern fn ZigClangVarDecl_getInit(*const ZigClangVarDecl) ?*const ZigClangExpr;
pub extern fn ZigClangVarDecl_getTLSKind(self: ?*const struct_ZigClangVarDecl) ZigClangVarDecl_TLSKind;
pub const ZigClangVarDecl_TLSKind = extern enum {
None,
Static,
Dynamic,
};

pub extern fn ZigClangImplicitCastExpr_getBeginLoc(*const ZigClangImplicitCastExpr) ZigClangSourceLocation;
pub extern fn ZigClangImplicitCastExpr_getCastKind(*const ZigClangImplicitCastExpr) ZigClangCK;
pub extern fn ZigClangImplicitCastExpr_getSubExpr(*const ZigClangImplicitCastExpr) *const ZigClangExpr;

pub extern fn ZigClangArrayType_getElementType(*const ZigClangArrayType) ZigClangQualType;

pub extern fn ZigClangDeclRefExpr_getDecl(*const ZigClangDeclRefExpr) *const ZigClangValueDecl;

pub extern fn ZigClangParenType_getInnerType(*const ZigClangParenType) ZigClangQualType;

pub extern fn ZigClangElaboratedType_getNamedType(*const ZigClangElaboratedType) ZigClangQualType;

pub extern fn ZigClangAttributedType_getEquivalentType(*const ZigClangAttributedType) ZigClangQualType;

pub extern fn ZigClangCStyleCastExpr_getBeginLoc(*const ZigClangCStyleCastExpr) ZigClangSourceLocation;
pub extern fn ZigClangCStyleCastExpr_getSubExpr(*const ZigClangCStyleCastExpr) *const ZigClangExpr;
pub extern fn ZigClangCStyleCastExpr_getType(*const ZigClangCStyleCastExpr) ZigClangQualType;

pub const ZigClangExprEvalResult = struct_ZigClangExprEvalResult;
pub const struct_ZigClangExprEvalResult = extern struct {
HasSideEffects: bool,
HasUndefinedBehavior: bool,
SmallVectorImpl: ?*c_void,
Val: ZigClangAPValue,
};

pub const struct_ZigClangAPValue = extern struct {
Kind: ZigClangAPValue_ValueKind,
Data: if (builtin.os == .windows) [52]u8 else [68]u8,
};

pub const ZigClangAPValue_ValueKind = extern enum {
ZigClangAPValue_ValueKind_Uninitialized,
ZigClangAPValue_ValueKind_Int,
ZigClangAPValue_ValueKind_Float,
ZigClangAPValue_ValueKind_ComplexInt,
ZigClangAPValue_ValueKind_ComplexFloat,
ZigClangAPValue_ValueKind_LValue,
ZigClangAPValue_ValueKind_Vector,
ZigClangAPValue_ValueKind_Array,
ZigClangAPValue_ValueKind_Struct,
ZigClangAPValue_ValueKind_Union,
ZigClangAPValue_ValueKind_MemberPointer,
ZigClangAPValue_ValueKind_AddrLabelDiff,
};

pub extern fn ZigClangIntegerLiteral_EvaluateAsInt(*const ZigClangIntegerLiteral, *ZigClangExprEvalResult, *const ZigClangASTContext) bool;
pub extern fn ZigClangIntegerLiteral_getBeginLoc(*const ZigClangIntegerLiteral) ZigClangSourceLocation;

pub extern fn ZigClangReturnStmt_getRetValue(*const ZigClangReturnStmt) ?*const ZigClangExpr;

pub extern fn ZigClangBinaryOperator_getOpcode(*const ZigClangBinaryOperator) ZigClangBO;
pub extern fn ZigClangBinaryOperator_getBeginLoc(*const ZigClangBinaryOperator) ZigClangSourceLocation;
pub extern fn ZigClangBinaryOperator_getLHS(*const ZigClangBinaryOperator) *const ZigClangExpr;
pub extern fn ZigClangBinaryOperator_getRHS(*const ZigClangBinaryOperator) *const ZigClangExpr;
pub extern fn ZigClangBinaryOperator_getType(*const ZigClangBinaryOperator) ZigClangQualType;

pub extern fn ZigClangStringLiteral_getKind(*const ZigClangStringLiteral) ZigClangStringLiteral_StringKind;
pub extern fn ZigClangStringLiteral_getString_bytes_begin_size(*const ZigClangStringLiteral, *usize) [*c]const u8;