Beispiel #1
0
    // Return the CodeDom type reference corresponding to T, or null
    public CodeTypeReference CppTypeToCodeDomType(CppType t, out bool byref)
    {
        CodeTypeReference rtype = null;

        byref = false;
        Type mtype = t.ToManagedType ();
        if (mtype != null) {
            if (mtype.IsByRef) {
                byref = true;
                mtype = mtype.GetElementType ();
            }
            return new CodeTypeReference (mtype);
        }

        if (t.Modifiers.Count > 0 && t.ElementType != CppTypes.Void && t.ElementType != CppTypes.Class)
            return null;
        switch (t.ElementType) {
        case CppTypes.Void:
            if (t.Modifiers.Count > 0) {
                if (t.Modifiers.Count == 1 && t.Modifiers [0] == CppModifiers.Pointer)
                    rtype = new CodeTypeReference (typeof (IntPtr));
                else
                    return null;
            } else {
                rtype = new CodeTypeReference (typeof (void));
            }
            break;
        case CppTypes.Bool:
            rtype = new CodeTypeReference (typeof (bool));
            break;
        case CppTypes.Int:
            rtype = new CodeTypeReference (typeof (int));
            break;
        case CppTypes.Float:
            rtype = new CodeTypeReference (typeof (float));
            break;
        case CppTypes.Double:
            rtype = new CodeTypeReference (typeof (double));
            break;
        case CppTypes.Char:
            rtype = new CodeTypeReference (typeof (char));
            break;
        case CppTypes.Class:
            // FIXME: Full name
            rtype = new CodeTypeReference (t.ElementTypeName);
            break;
        default:
            return null;
        }
        return rtype;
    }
Beispiel #2
0
			public TemplateModifier (CppType [] types)
			{
				Types = types;
			}
Beispiel #3
0
 CppType GetType(Node n, CppType modifiers)
 {
     switch (n.Type) {
     case "ArrayType":
         return GetType (GetTypeNode (n), modifiers.Modify (CppModifiers.Array));
     case "PointerType":
         return GetType (GetTypeNode (n), modifiers.Modify (CppModifiers.Pointer));
     case "ReferenceType":
         return GetType (GetTypeNode (n), modifiers.Modify (CppModifiers.Reference));
     case "FundamentalType":
         return modifiers.CopyTypeFrom (new CppType (n.Name));
     case "CvQualifiedType":
         if (n.IsTrue ("const"))
             return GetType (GetTypeNode (n), modifiers.Modify (CppModifiers.Const));
         else
             throw new NotImplementedException ();
     case "Class":
     case "Struct":
         if (!NodeToClass.ContainsKey (n)) {
             if (modifiers.Modifiers.Count () == 1 && modifiers.Modifiers [0] == CppModifiers.Pointer)
                 // Map these to void*
                 return modifiers.CopyTypeFrom (CppTypes.Void);
             else
                 return CppTypes.Unknown;
         }
         return modifiers.CopyTypeFrom (new CppType (CppTypes.Class, NodeToClass [n].Name));
     default:
         return CppTypes.Unknown;
     }
 }
Beispiel #4
0
 public Parameter(String name, CppType type)
 {
     Name = name;
     Type = type;
 }
Beispiel #5
0
    public CodeTypeReference CppTypeToCodeDomType(CppType t)
    {
        bool byref;

        return CppTypeToCodeDomType (t, out byref);
    }
Beispiel #6
0
		// Applies the element type of the passed instance
		//  and combines its modifiers into this instance.
		//  Use when THIS instance may have attributes you want,
		//  but want the element type of the passed instance.
		public CppType CopyTypeFrom (CppType type)
		{
			ElementType = type.ElementType;
			ElementTypeName = type.ElementTypeName;
			Namespaces = type.Namespaces;

			List<CppModifiers> oldModifiers = internalModifiers;
			internalModifiers = type.internalModifiers;

			if (oldModifiers != null)
				Modifiers.AddRange (oldModifiers);

			return this;
		}
Beispiel #7
0
		// Removes the modifiers on the passed instance from this instance
		public CppType Subtract (CppType type)
		{
			if (internalModifiers == null)
				return this;

			CppType current = this;
			foreach (var modifier in ((IEnumerable<CppModifiers>)type.Modifiers).Reverse ())
				current = current.Subtract (modifier);

			return current;
		}
Beispiel #8
0
 public MangleAsAttribute(CppType mangleType)
 {
     this.MangleType = mangleType;
 }
Beispiel #9
0
        public virtual CppType GetMangleType(ICustomAttributeProvider icap, Type managedType)
        {
            CppType mangleType = new CppType ();
            MangleAsAttribute maa = (MangleAsAttribute)icap.GetCustomAttributes (typeof (MangleAsAttribute), false).FirstOrDefault ();
            if (maa != null)
                mangleType = maa.MangleType;

            // this means that either no MangleAsAttribute was defined, or
            //  only CppModifiers were applied .. apply CppType from managed parameter type
            if (mangleType.ElementType == CppTypes.Unknown && mangleType.ElementTypeName == null)
                mangleType.CopyTypeFrom (CppType.ForManagedType (managedType));
            else if (mangleType.ElementType == CppTypes.Unknown)
                // FIXME: otherwise, we just assume it's CppTypes.Class for now.
                mangleType.ElementType = CppTypes.Class;

            return mangleType;
        }
Beispiel #10
0
 public Field(string name, CppType type)
 {
     Name = name;
     Type = type;
 }
Beispiel #11
0
 public Property(string name, CppType type)
 {
     Name = name;
     Type = type;
 }
Beispiel #12
0
        public virtual string GetTypeCode(CppType mangleType)
        {
            CppTypes element = mangleType.ElementType;
            IEnumerable<CppModifiers> modifiers = mangleType.Modifiers;

            StringBuilder code = new StringBuilder ();

            var ptr = For.AnyInputIn (CppModifiers.Pointer);
            var ptrRefOrArray = For.AnyInputIn (CppModifiers.Pointer, CppModifiers.Reference, CppModifiers.Array);

            var modifierCode = modifiers.Reverse ().Transform (

                Choose.TopOne (
                    For.AllInputsIn (CppModifiers.Const, CppModifiers.Volatile).InAnyOrder ().After (ptrRefOrArray).Emit ('D'),
                            For.AnyInputIn (CppModifiers.Const).After (ptrRefOrArray).Emit ('B'),
                    For.AnyInputIn (CppModifiers.Volatile).After (ptrRefOrArray).Emit ('C'),
                            For.AnyInput<CppModifiers> ().After (ptrRefOrArray).Emit ('A')
                    ),

                For.AnyInputIn (CppModifiers.Array).Emit ('Q'),
                For.AnyInputIn (CppModifiers.Reference).Emit ('A'),

                Choose.TopOne (
                            ptr.After ().AllInputsIn (CppModifiers.Const, CppModifiers.Volatile).InAnyOrder ().Emit ('S'),
                    ptr.After ().AnyInputIn (CppModifiers.Const).Emit ('Q'),
                            ptr.After ().AnyInputIn (CppModifiers.Volatile).Emit ('R'),
                            ptr.Emit ('P')
                                ),

                    ptrRefOrArray.AtEnd ().Emit ('A')
            );
            code.Append (modifierCode.ToArray ());

            switch (element) {
            case CppTypes.Void:
                code.Append ('X');
                break;
            case CppTypes.Int:
                code.Append (modifiers.Transform (
                    For.AllInputsIn (CppModifiers.Unsigned, CppModifiers.Short).InAnyOrder ().Emit ('G')
                ).DefaultIfEmpty ('H').ToArray ());
                break;
            case CppTypes.Char:
                code.Append ('D');
                break;
            case CppTypes.Class:
                code.Append ('V');
                code.Append(mangleType.ElementTypeName);
                code.Append ("@@");
                break;
            case CppTypes.Struct:
                code.Append ('U');
                code.Append(mangleType.ElementTypeName);
                code.Append ("@@");
                break;
            case CppTypes.Union:
                code.Append ('T');
                code.Append(mangleType.ElementTypeName);
                code.Append ("@@");
                break;
            case CppTypes.Enum:
                code.Append ("W4");
                code.Append(mangleType.ElementTypeName);
                code.Append ("@@");
                break;
            }

            return code.ToString ();
        }