Exemplo n.º 1
0
        private bool addClassPriv(COOPClass coopClass, out Node createdNode)
        {
            Node parent = null;

            if (contains(coopClass))
            {
                createdNode = this[coopClass];
                return(false);
            }

            if (coopClass.Parent != null)
            {
                if (!contains(coopClass.Parent))
                {
                    addClassPriv(coopClass.Parent, out parent);
                }
                else
                {
                    parent = this[coopClass.Parent];
                }
            }

            Node newNode = new Node(coopClass, parent);

            createdNode = newNode;
            return(true);
        }
Exemplo n.º 2
0
        private string publicStruct()
        {
            Field[]   publicFields      = @class.getFields(AccessLevel.Public, AccessLevelRule.equals);
            COOPClass parentClass       = hierarchy.findNextAvailableParentClass(@class);
            string    parentClassString = hasParent? "" : parentClass.toUsableToC() + " super;\n";

            string publicFieldsString = "";

            foreach (Field publicField in publicFields)
            {
                string type = hierarchy.findNextAvailableParentClass((COOPClass)publicField.type).toUsableToC();
                publicFieldsString += $"{type} {publicField.name};\n";
            }

            return($@"
{@class.toUsableToC()}{{
	{parentClassString}
	struct type_info t_info;
	struct function_references *functions;
	struct {@class.Name}_external_references external;
	struct {@class.Name}_protected protected;
	struct {@class.Name}_private private;
	{publicFieldsString}
}};");
        }
Exemplo n.º 3
0
        public bool addClass(COOPClass coopClass)
        {
            Node t;

            addClassPriv(coopClass, out t);
            return(t != null);
        }
        private COOPClass getReturnTypeForFunction(COOPClass original, string name)
        {
            COOPClass c      = original;
            COOPClass output = null;

            while (output == null)
            {
                if (c.Functions.TryGetValue(name, out COOPFunction f))
                {
                    output = f.ReturnType;
                }

                if (hierarchy.getParent(c) != null)
                {
                    c = hierarchy.getParent(c);
                }
                else
                {
                    break;
                }
            }


            return(output);
        }
Exemplo n.º 5
0
        private COOPClass calculateLowestMemberCoopClass(ParseNode o, COOPClass p)
        {
            if (!o.Equals("<member>"))
            {
                return(null);
            }
            if (!o.Contains("<member>"))
            {
                return(variablesToType[o.terminals]);
            }

            ParseNode ptr     = o;
            COOPClass current = p;

            while (ptr.Contains("<member>"))
            {
                string memberName = ptr["<symbol>"].terminals;
                if (o.Contains("<function_call>"))
                {
                    current = current.Functions[memberName].ReturnType;
                }
                else
                {
                    current = current.VarNames[memberName];
                }

                ptr = ptr["<member>"];
            }

            return(current);
        }
        static IncludedClasses()
        {
            Object = new COOPClass("Object", null);
            String = new COOPClass("String");

            COOPFunction ToString = new COOPFunction(Ownership <COOPClass> .ownership(Object), String, "ToString");
        }
 public COOPFunction(Ownership <COOPClass> ownership, COOPClass returnType, string name)
 {
     this.ownership   = ownership;
     this.returnType  = returnType;
     this.name        = name;
     bodies           = new Collection <Body>();
     inputsListToBody = new Dictionary <InputList, Body>();
 }
        private List <string> getAvailableMangledNames(COOPClass coopClass)
        {
            List <COOPFunction> functions = getAvailableFunctions(coopClass, classHierarchy);
            List <string>       output    = new  List <string>();

            output.AddRange(from f in functions select getMangledName(f.Name, f.InputTypes));

            return(output);
        }
Exemplo n.º 9
0
 public Node(COOPClass @class, Node parent)
 {
     this.@class = @class;
     children    = new List <Node>();
     this.parent = parent;
     if (parent != null)
     {
         parent.Add(this);
     }
 }
 public CallChain(Dictionary <NameInputTypePair, string> originalNameAndInputTypesToMangledName, Dictionary <NameInputTypePair, bool> originalNameAndInputTypesToisStatic, Dictionary <string, COOPClass> functionToReturnType, Dictionary <string, COOPClass> availableClasses, Dictionary <string, COOPClass> variablesToType, Dictionary <string, bool> isClassDict, COOPClass parentClass, ClassHierarchy hierarchy)
 {
     this.originalNameAndInputTypesToMangledName = originalNameAndInputTypesToMangledName;
     this.originalNameAndInputTypesToisStatic    = originalNameAndInputTypesToisStatic;
     this.functionToReturnType = functionToReturnType;
     this.availableClasses     = availableClasses;
     this.variablesToType      = variablesToType;
     this.isClassDict          = isClassDict;
     this.parentClass          = parentClass;
     this.hierarchy            = hierarchy;
 }
 public COOPFunctionConverter(ClassHierarchy hierarchy, COOPClass parentClass)
 {
     classHierarchy   = hierarchy;
     this.parentClass = parentClass;
     originalNameAndInputTypesToMangledName = new Dictionary <NameInputTypePair, string>(NameInputTypePair.nameInputsComparer);
     originalNameAndInputTypesToisStatic    = new Dictionary <NameInputTypePair, bool>();
     functionToReturnType = new Dictionary <string, COOPClass>();
     availableClasses     = hierarchy.getLineage(parentClass);
     availableClasses.AddRange(parentClass.imports);
     generateDictionaries();
 }
        public bool add(COOPClass coopClass, COOPClass parent)
        {
            var node = find(parent, head);

            if (node == null)
            {
                return(false);
            }
            Node parentNode = node;

            parentNode.children.Add(new Node(coopClass, parentNode));
            return(true);
        }
Exemplo n.º 13
0
        public List <COOPClass> getLineage(COOPClass coopClass)
        {
            if (getParent(coopClass) == null)
            {
                return new List <COOPClass> {
                           coopClass
                }
            }
            ;
            List <COOPClass> output = new List <COOPClass>(getLineage(coopClass.Parent));

            output.Add(coopClass);
            return(output);
        }
        static COOPPrimitives()
        {
            @long   = new PrimitiveCOOPClass("long");
            integer = new PrimitiveCOOPClass("int");
            @short  = new PrimitiveCOOPClass("short");
            @byte   = new PrimitiveCOOPClass("byte");

            @ulong   = new PrimitiveCOOPClass("unsigned_long");
            uinteger = new PrimitiveCOOPClass("unsigned_int");
            @ushort  = new PrimitiveCOOPClass("unsigned_short");
            @ubyte   = new PrimitiveCOOPClass("unsigned_byte");

            @float  = new PrimitiveCOOPClass("float");
            @double = new PrimitiveCOOPClass("double");
        }
Exemplo n.º 15
0
        private bool contains(Node n, COOPClass coopClass)
        {
            if (n.NodeClass.Equals(coopClass))
            {
                return(true);
            }
            foreach (Node nChild in n.Children)
            {
                if (contains(nChild, coopClass))
                {
                    return(true);
                }
            }

            return(false);
        }
        private Node find(COOPClass coopClass, Node ptr)
        {
            if (ptr.coopClass == coopClass)
            {
                return(ptr);
            }
            foreach (Node ptrChild in ptr.children)
            {
                var node = find(coopClass, ptrChild);
                if (node != null)
                {
                    return(node);
                }
            }

            return(null);
        }
Exemplo n.º 17
0
            public Node find(COOPClass coopClass)
            {
                if (@class.Equals(coopClass))
                {
                    return(this);
                }

                foreach (Node child in children)
                {
                    Node f = child.find(coopClass);
                    if (f != null)
                    {
                        return(f);
                    }
                }

                return(null);
            }
        private List <COOPFunction> getAvailableFunctions(COOPClass coopClass, ClassHierarchy hierarchy)
        {
            List <COOPFunction> output = new List <COOPFunction>(coopClass.Functions.Values);

            List <COOPClass> lineageClasses = new List <COOPClass>(hierarchy.getLineage(coopClass));

            lineageClasses.Remove(coopClass);

            foreach (COOPClass lineageClass in lineageClasses)
            {
                output.AddRange(from f in lineageClass.Functions.Values where (int)f.AccessLevel >= 1 select f);
            }
            foreach (COOPClass coopClassImport in coopClass.imports)
            {
                output.AddRange(from f in coopClassImport.Functions.Values where f.AccessLevel == AccessLevel.Public select f);
            }

            return(output);
        }
        private ObjectFunctionCallNode createObjectFunctionCall(CallNode parent, ParseNode s, ParseNode f)
        {
            if (!s.Equals("<symbol>") || !f.Equals("<function_call>"))
            {
                return(null);
            }
            COOPClass type = getReturnTypeForFunction(parent.type, s.terminals);
            ObjectFunctionCallNode output = new ObjectFunctionCallNode(
                type,
                s.terminals,
                parent
                );

            foreach (ParseNode node in Parser.ConvertListNodeToListOfListObjects(f["<list_object>"]))
            {
                output.parameters.Add(createCallNodeChain(node));
            }

            return(output);
        }
Exemplo n.º 20
0
        private CallReturn calculateObject(ParseNode o)
        {
            if (!o.Equals("<object>"))
            {
                return(null);
            }

            CallChain c = new CallChain(originalNameAndInputTypesToMangledName,
                                        originalNameAndInputTypesToisStatic,
                                        functionToReturnType,
                                        availableClasses,
                                        variablesToType,
                                        isClassDict,
                                        parentClass,
                                        hierarchy);

            CallChain.CallNode n = c.createCallNodeChain(o);
            Console.WriteLine(n);
            COOPClass returnType = n.type;
            string    fixedForC  = c.fixForC(n);

            return(new CallReturn(fixedForC, returnType));
        }
 public ClassCallNode(COOPClass type) : base(type, "this")
 {
 }
 public SymbolNode(COOPClass type, string symbol) : base(type)
 {
     this.symbol = symbol;
 }
 public CallNode(COOPClass type)
 {
     this.type = type;
 }
 public ObjectFunctionCallNode(COOPClass type, string symbol, CallNode parentObject) : base(type, symbol)
 {
     this.parentObject = parentObject;
 }
 public StaticFunctionCallNode(COOPClass type, string symbol, COOPClass @class) : base(type, symbol)
 {
     this.@class = @class;
 }
Exemplo n.º 26
0
 public COOPClassFileCreator(AdvancedTypeHierarchy hierarchy, COOPClass @class)
 {
     this.hierarchy = hierarchy;
     this.@class    = @class;
 }
Exemplo n.º 27
0
 public COOPClass getParent(COOPClass coopClass)
 {
     return(this[coopClass.Parent]?.NodeClass);
 }
 public CastCallNode(COOPClass type, CallNode parentObject) : base(type, $"cast<{type}>", parentObject)
 {
 }
 public FunctionCallNode(COOPClass type, string symbol) : base(type, symbol)
 {
     parameters = new List <CallNode>();
 }
Exemplo n.º 30
0
 private Node this[COOPClass className] => head.find(className);