/// <summary>
 /// Creates a new function.
 /// </summary>
 /// <param name="name">The name of this function.</param>
 /// <param name="returnType">The return type of this function, including reference type.</param>
 /// <param name="accessModifier">The access modifier for this function.</param>
 /// <param name="isVirtual">Whether this function is virtual, i.e., designed to be overriden.</param>
 /// <param name="args">A list of arguments to this function.</param>
 public FunctionDeclaration(string name, TypeReference returnType, AccessLevel accessModifier, bool isVirtual, params VariableDeclaration[] args)
 {
     Name = name;
     ReturnType = returnType;
     AccessModifier = accessModifier;
     Virtual = isVirtual;
     Arguments = args.ToList();
 }
        static void Main(string[] args)
        {
            var myClass = new ClassDeclaration("CMyClass");

            // Add a private field
            myClass.Fields.Add(new FieldDeclaration("m_someInt", Primitive.Int, AccessLevel.Private));

            // Define our custom type
            var myType = new TypeReference("CSomeOtherClass").MakePointer();

            // And store a private pointer with a basic comment
            myClass.Fields.Add(new FieldDeclaration("m_pSomePointer", myType, AccessLevel.Private,
                new Comment("Test comment")));

            // Add getters
            myClass.Functions.Add(new FunctionDeclaration("GetInteger", Primitive.Int));
            myClass.Functions.Add(new FunctionDeclaration("GetOtherClass", myType));

            // And setters
            var intArg = new VariableDeclaration("value", Primitive.Int);
            var classPtrArg = new VariableDeclaration("value", myType);

            myClass.Functions.Add(new FunctionDeclaration("SetInteger", Primitive.Void,
                AccessLevel.Public, false, intArg));
            myClass.Functions.Add(new FunctionDeclaration("SetOtherClass", Primitive.Void,
                AccessLevel.Public, false, classPtrArg));

            // Add a virtual function with a multiline comment
            var comment = new MultilineComment("This is a function",
                "that should be overridden",
                "just because it can be");

            var function = new FunctionDeclaration("OverrideMe", Primitive.Char.MakePointer().MakeConst(),
                AccessLevel.Public, true);

            function.Comment = comment;
            myClass.Functions.Add(function);

            var classSource = myClass.CreateSource();

            Console.Write(myClass.CreateSource());
            Console.ReadLine();
        }
 /// <summary>
 /// Creates a new VariableDeclaration.
 /// </summary>
 /// <param name="name">The name of this variable.</param>
 /// <param name="type">The type of this variable, including reference type.</param>
 /// <param name="comment">Optionally, a comment for this field, to aid in documentation.</param>
 public VariableDeclaration(string name, TypeReference type, IComment comment = null)
 {
     Name = name;
     Type = type;
     Comment = comment;
 }
Esempio n. 4
0
 public TypeReference(TypeReference type)
     : this(type.Name, type.ReferenceType, type.Static, type.Const, type.Signed, type.Length)
 {
 }
Esempio n. 5
0
 public TypeReference MakeReference()
 {
     var newType = new TypeReference(this);
     newType.ReferenceType = ReferenceModifier.Reference;
     return newType;
 }
Esempio n. 6
0
 public TypeReference MakePointer()
 {
     var newType = new TypeReference(this);
     newType.ReferenceType = ReferenceModifier.Pointer;
     return newType;
 }
Esempio n. 7
0
 public TypeReference MakeConst()
 {
     var newType = new TypeReference(this);
     newType.Const = true;
     return newType;
 }
Esempio n. 8
0
        public static TypeReference Create(string name, params string[] tokenArgs)
        {
            var classRef = new TypeReference(name);
            var tokens = tokenArgs.ToList();

            while(tokens.Count > 0)
            {
                var token = tokens.First();

                switch(token)
                {
                    case "unsigned":
                        classRef.Signed = false;
                        break;

                    case "long":
                        classRef.Length = classRef.Length == LengthModifier.Long ? LengthModifier.LongLong : LengthModifier.Long;
                        break;

                    case "short":
                        classRef.Length = LengthModifier.Short;
                        break;

                    case "static":
                        classRef.Static = true;
                        break;

                    case "const":
                        classRef.Const = true;
                        break;
                }

                tokens.RemoveAt(0);
            }

            return classRef;
        }
 /// <summary>
 /// Creates a new non-virtual function.
 /// </summary>
 /// <param name="name">The name of this function.</param>
 /// <param name="returnType">The return type of this function, including reference type.</param>
 /// <param name="accessModifier">The access modifier for this function.</param>
 public FunctionDeclaration(string name, TypeReference returnType, AccessLevel accessModifier)
     : this(name, returnType, accessModifier, false)
 {
 }
 /// <summary>
 /// Creates a new public non-virtual function.
 /// </summary>
 /// <param name="name">The name of this function.</param>
 /// <param name="returnType">The return type of this function, including reference type.</param>
 public FunctionDeclaration(string name, TypeReference returnType)
     : this(name, returnType, AccessLevel.Public, false)
 {
 }