authorgravatar for thejoshwolfe@gmail.comJosh Wolfe <thejoshwolfe@gmail.com> 2017-09-01 11:42:48-07:00
committergravatar for thejoshwolfe@gmail.comJosh Wolfe <thejoshwolfe@gmail.com> 2017-09-01 11:42:48-07:00
loga260cfa4dd7837668b44432335f88c09b12423cd
tree54dff0ca22586abfdbc0623b45c489f97cd50857
parent0d0fffe4d22169e5dae08e88c0fb6c1b56824c61
parent80d75cf3bf2a1ec72e1ca2e03c599a72261e9604

Merge remote-tracking branch 'origin/c-to-zig' into c-to-zig


1 files changed, 181 insertions(+), 0 deletions(-)

src/parseh.cpp+181
...@@ -43,7 +43,10 @@ struct Context {...@@ -43,7 +43,10 @@ struct Context {
43 ZigList<ErrorMsg *> *errors;43 ZigList<ErrorMsg *> *errors;
44 bool warnings_on;44 bool warnings_on;
45 VisibMod visib_mod;45 VisibMod visib_mod;
46
46 HashMap<Buf *, TypeTableEntry *, buf_hash, buf_eql_buf> global_type_table;47 HashMap<Buf *, TypeTableEntry *, buf_hash, buf_eql_buf> global_type_table;
48 HashMap<Buf *, AstNode *, buf_hash, buf_eql_buf> global_type_table2;
49
47 HashMap<Buf *, TypeTableEntry *, buf_hash, buf_eql_buf> struct_type_table;50 HashMap<Buf *, TypeTableEntry *, buf_hash, buf_eql_buf> struct_type_table;
48 HashMap<Buf *, TypeTableEntry *, buf_hash, buf_eql_buf> enum_type_table;51 HashMap<Buf *, TypeTableEntry *, buf_hash, buf_eql_buf> enum_type_table;
49 HashMap<const void *, TypeTableEntry *, ptr_hash, ptr_eq> decl_table;52 HashMap<const void *, TypeTableEntry *, ptr_hash, ptr_eq> decl_table;
...@@ -670,6 +673,184 @@ static AstNode * trans_expr(Context *c, AstNode *block, Expr *expr) {...@@ -670,6 +673,184 @@ static AstNode * trans_expr(Context *c, AstNode *block, Expr *expr) {
670 return trans_stmt(c, block, expr);673 return trans_stmt(c, block, expr);
671}674}
672675
676static AstNode *trans_type_with_table(Context *c, const Type *ty, const SourceLocation &source_loc,
677 HashMap<Buf *, AstNode *, buf_hash, buf_eql_buf> *type_table)
678{
679 switch (ty->getTypeClass()) {
680 case Type::Builtin:
681 {
682 const BuiltinType *builtin_ty = static_cast<const BuiltinType*>(ty);
683 switch (builtin_ty->getKind()) {
684 case BuiltinType::Void:
685 zig_panic("TODO void type");
686 case BuiltinType::Bool:
687 zig_panic("TODO bool type");
688 case BuiltinType::Char_U:
689 case BuiltinType::UChar:
690 case BuiltinType::Char_S:
691 zig_panic("TODO u8 type");
692 case BuiltinType::SChar:
693 zig_panic("TODO i8 type");
694 case BuiltinType::UShort:
695 zig_panic("TODO c_ushort type");
696 case BuiltinType::UInt:
697 zig_panic("TODO c_uint type");
698 case BuiltinType::ULong:
699 zig_panic("TODO c_ulong type");
700 case BuiltinType::ULongLong:
701 zig_panic("TODO c_ulonglong type");
702 case BuiltinType::Short:
703 zig_panic("TODO c_short type");
704 case BuiltinType::Int:
705 zig_panic("TODO c_int type");
706 case BuiltinType::Long:
707 zig_panic("TODO c_long type");
708 case BuiltinType::LongLong:
709 zig_panic("TODO c_longlong type");
710 case BuiltinType::UInt128:
711 zig_panic("TODO u128 type");
712 case BuiltinType::Int128:
713 zig_panic("TODO i128 type");
714 case BuiltinType::Float:
715 zig_panic("TODO f32 type");
716 case BuiltinType::Double:
717 zig_panic("TODO f64 type");
718 case BuiltinType::Float128:
719 zig_panic("TODO f128 type");
720 case BuiltinType::LongDouble:
721 zig_panic("TODO c_longdouble type");
722 case BuiltinType::WChar_U:
723 case BuiltinType::Char16:
724 case BuiltinType::Char32:
725 case BuiltinType::WChar_S:
726 case BuiltinType::Half:
727 case BuiltinType::NullPtr:
728 case BuiltinType::ObjCId:
729 case BuiltinType::ObjCClass:
730 case BuiltinType::ObjCSel:
731 case BuiltinType::OMPArraySection:
732 case BuiltinType::Dependent:
733 case BuiltinType::Overload:
734 case BuiltinType::BoundMember:
735 case BuiltinType::PseudoObject:
736 case BuiltinType::UnknownAny:
737 case BuiltinType::BuiltinFn:
738 case BuiltinType::ARCUnbridgedCast:
739
740 case BuiltinType::OCLImage1dRO:
741 case BuiltinType::OCLImage1dArrayRO:
742 case BuiltinType::OCLImage1dBufferRO:
743 case BuiltinType::OCLImage2dRO:
744 case BuiltinType::OCLImage2dArrayRO:
745 case BuiltinType::OCLImage2dDepthRO:
746 case BuiltinType::OCLImage2dArrayDepthRO:
747 case BuiltinType::OCLImage2dMSAARO:
748 case BuiltinType::OCLImage2dArrayMSAARO:
749 case BuiltinType::OCLImage2dMSAADepthRO:
750 case BuiltinType::OCLImage2dArrayMSAADepthRO:
751 case BuiltinType::OCLImage3dRO:
752 case BuiltinType::OCLImage1dWO:
753 case BuiltinType::OCLImage1dArrayWO:
754 case BuiltinType::OCLImage1dBufferWO:
755 case BuiltinType::OCLImage2dWO:
756 case BuiltinType::OCLImage2dArrayWO:
757 case BuiltinType::OCLImage2dDepthWO:
758 case BuiltinType::OCLImage2dArrayDepthWO:
759 case BuiltinType::OCLImage2dMSAAWO:
760 case BuiltinType::OCLImage2dArrayMSAAWO:
761 case BuiltinType::OCLImage2dMSAADepthWO:
762 case BuiltinType::OCLImage2dArrayMSAADepthWO:
763 case BuiltinType::OCLImage3dWO:
764 case BuiltinType::OCLImage1dRW:
765 case BuiltinType::OCLImage1dArrayRW:
766 case BuiltinType::OCLImage1dBufferRW:
767 case BuiltinType::OCLImage2dRW:
768 case BuiltinType::OCLImage2dArrayRW:
769 case BuiltinType::OCLImage2dDepthRW:
770 case BuiltinType::OCLImage2dArrayDepthRW:
771 case BuiltinType::OCLImage2dMSAARW:
772 case BuiltinType::OCLImage2dArrayMSAARW:
773 case BuiltinType::OCLImage2dMSAADepthRW:
774 case BuiltinType::OCLImage2dArrayMSAADepthRW:
775 case BuiltinType::OCLImage3dRW:
776 case BuiltinType::OCLSampler:
777 case BuiltinType::OCLEvent:
778 case BuiltinType::OCLClkEvent:
779 case BuiltinType::OCLQueue:
780 case BuiltinType::OCLReserveID:
781 zig_panic("TODO more c type");
782 }
783 break;
784 }
785 case Type::Pointer:
786 zig_panic("TODO pointer");
787 case Type::Typedef:
788 zig_panic("TODO typedef");
789 case Type::Elaborated:
790 zig_panic("TODO elaborated");
791 case Type::FunctionProto:
792 zig_panic("TODO FunctionProto");
793 case Type::Record:
794 zig_panic("TODO Record");
795 case Type::Enum:
796 zig_panic("TODO Enum");
797 case Type::ConstantArray:
798 zig_panic("TODO ConstantArray");
799 case Type::Paren:
800 zig_panic("TODO Paren");
801 case Type::Decayed:
802 zig_panic("TODO Decayed");
803 case Type::Attributed:
804 zig_panic("TODO Attributed");
805 case Type::BlockPointer:
806 case Type::LValueReference:
807 case Type::RValueReference:
808 case Type::MemberPointer:
809 case Type::IncompleteArray:
810 case Type::VariableArray:
811 case Type::DependentSizedArray:
812 case Type::DependentSizedExtVector:
813 case Type::Vector:
814 case Type::ExtVector:
815 case Type::FunctionNoProto:
816 case Type::UnresolvedUsing:
817 case Type::Adjusted:
818 case Type::TypeOfExpr:
819 case Type::TypeOf:
820 case Type::Decltype:
821 case Type::UnaryTransform:
822 case Type::TemplateTypeParm:
823 case Type::SubstTemplateTypeParm:
824 case Type::SubstTemplateTypeParmPack:
825 case Type::TemplateSpecialization:
826 case Type::Auto:
827 case Type::InjectedClassName:
828 case Type::DependentName:
829 case Type::DependentTemplateSpecialization:
830 case Type::PackExpansion:
831 case Type::ObjCObject:
832 case Type::ObjCInterface:
833 case Type::Complex:
834 case Type::ObjCObjectPointer:
835 case Type::Atomic:
836 case Type::Pipe:
837 case Type::ObjCTypeParam:
838 case Type::DeducedTemplateSpecialization:
839 zig_panic("TODO more c type aoeu");
840 }
841 zig_unreachable();
842}
843
844static AstNode * trans_qual_type_with_table(Context *c, QualType qt, const SourceLocation &source_loc,
845 HashMap<Buf *, AstNode *, buf_hash, buf_eql_buf> *type_table)
846{
847 return trans_type_with_table(c, qt.getTypePtr(), source_loc, type_table);
848}
849
850static AstNode * trans_qual_type(Context *c, QualType qt, const SourceLocation &source_loc) {
851 return trans_qual_type_with_table(c, qt, source_loc, &c->global_type_table2);
852}
853
673static AstNode * trans_create_node(Context *c, Stmt *stmt, NodeType id) {854static AstNode * trans_create_node(Context *c, Stmt *stmt, NodeType id) {
674 AstNode *node = allocate<AstNode>(1);855 AstNode *node = allocate<AstNode>(1);
675 node->type = id;856 node->type = id;