Beispiel #1
0
	CppType GetType (Node n, CppType modifiers) {
		var fundamental = CppTypes.Unknown;

		switch (n.Type) {
		case "Typedef":
			return GetType (GetTypeNode (n), modifiers);
		case "ArrayType":
			CppModifiers mod = null;
			if (n.Attributes ["max"] != null && n.Attributes ["min"] != null)
				mod = new CppModifiers.ArrayModifier (int.Parse (n.Attributes ["max"].TrimEnd ('u')) - int.Parse (n.Attributes ["min"].TrimEnd ('u')) + 1);
			else
				mod = CppModifiers.Array;
			return GetType (GetTypeNode (n), modifiers.Modify (mod));
		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":
			fundamental = CppTypes.Class;
			break;
		case "Struct":
			fundamental = CppTypes.Struct;
			break;
		case "Enumeration":
			fundamental = CppTypes.Enum;
			break;
		default:
			return CppTypes.Unknown;
		}

		if (!NodeToNamespace.ContainsKey (n)) {
			// FIXME: Do something better
			return CppTypes.Unknown;
		}

		return modifiers.CopyTypeFrom (new CppType (fundamental, string.Join ("::", NodeToNamespace [n].FullyQualifiedName)));
	}
Beispiel #2
0
    CppType GetType(Node n, CppType modifiers)
    {
        var fundamental = CppTypes.Unknown;

        switch (n.Type) {
        case "Typedef":
            return GetType (GetTypeNode (n), modifiers);
        case "ArrayType":
            CppModifiers mod = null;
                var max = n.Attributes ["max"];
                var min = n.Attributes ["min"];
                if (max != null && min != null)
                {
                    var l = GetLongValue (max) - GetLongValue (min);
                    mod = new CppModifiers.ArrayModifier ((int)l + 1);
                }
                else
                {
                    mod = CppModifiers.Array;
                }
                return GetType(GetTypeNode(n), modifiers.Modify(mod));
        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":
            fundamental = CppTypes.Class;
            break;
        case "Struct":
            fundamental = CppTypes.Struct;
            break;
        case "Enumeration":
            fundamental = CppTypes.Enum;
            break;
        case "FunctionType":
            fundamental = CppTypes.Delegate;
            break;
        default:
            return CppTypes.Unknown;
        }

        if (!NodeToNamespace.ContainsKey (n)) {
            // FIXME: Do something better
            if(string.IsNullOrEmpty(n.Name))
            {
                Console.WriteLine ("WARNING: Could not find type with id '{0}'", n.Id);
            }
            else
            {
                Console.WriteLine ("WARNING: Could not find type '{0}'", n.Name);
            }

            return CppTypes.Unknown;
        }

        return modifiers.CopyTypeFrom (new CppType (fundamental, string.Join ("::", NodeToNamespace [n].FullyQualifiedName)));
    }