private void HandleLocalVariableDeclarationContext(CodeBlock inCodeBlock, LocalVariableDeclarationContext tmpVar) { var tmpVarDeclaration = new VariableDeclaration(); if (tmpVar.typeType() != null) { tmpVarDeclaration.Type = JavaAntlrClassLoader.GetTypeContainer(tmpVar.typeType()); } if (tmpVar.variableDeclarators() != null) { foreach (var tmpVariableDeclaration in tmpVar.variableDeclarators().variableDeclarator()) { var tmpVarDec = new VariableDeclaration() { Type = tmpVarDeclaration.Type, Name = tmpVariableDeclaration.variableDeclaratorId().GetText(), }; inCodeBlock.CodeEntries.Add(tmpVarDec); if (tmpVariableDeclaration.variableInitializer() != null) { HandleArrayInizializer(inCodeBlock, tmpVariableDeclaration.variableInitializer().arrayInitializer(), tmpVarDec); HandleExpressionContext(inCodeBlock, tmpVariableDeclaration.variableInitializer().expression(), tmpVarDec); } } } if (tmpVar.variableModifier().Length > 0) { throw new NotImplementedException("Not done yet"); } }
public ProjectInformation CreateObjectInformation(List <string> inFileContents, IniParser.Model.IniData inConfiguration) { var tmpClassList = new List <ClassContainer>(); ProjectInformation tmpObjectInformation = new ProjectInformation(); if (LoadDefaultData) { tmpObjectInformation = ProjectInformationHelper.CreateSystemProjectInformation(ImportHelper.ImportClasses(JavaLangClassJson.JavaLang), ImportHelper.ImportAliasList(CompilerAliasHelper.SystemAliasJson), "java.lang"); } foreach (var tmpFile in inFileContents) { //tmpClassList.AddRange(JavaClassLoader.LoadFile(tmpFile)); tmpClassList.AddRange(JavaAntlrClassLoader.LoaderOptimization(tmpFile)); } tmpObjectInformation.FillClasses(tmpClassList); //Add Mapped Methodes to Class List (So we don't need String oä as a Class List var tmpAdditionalClasses = new List <ClassContainer>(); //Load all Classes, with Methodes we might need if (inConfiguration != null) { foreach (var tmpMap in inConfiguration["Methode"]) { var tmpLeftSplit = tmpMap.KeyName.Split('.'); var tmpNamespace = string.Join(".", tmpLeftSplit.SkipLast(2)); var tmpName = (TypeContainer)tmpLeftSplit.SkipLast(1).Last(); var tmpMethodeName = tmpLeftSplit.Last(); var tmpClass = tmpAdditionalClasses.FirstOrDefault(inItem => inItem.Namespace == tmpNamespace && inItem.Type == tmpName); if (tmpClass == null) { tmpClass = new ClassContainer { Type = tmpName, Namespace = tmpNamespace }; tmpAdditionalClasses.Add(tmpClass); } if (!tmpClass.MethodeList.Any(inItem => inItem.Name == tmpMethodeName)) { //TODO Check for Param Equality if (tmpClass.MethodeList.Count(inItem => inItem.Name == tmpMethodeName) > 1) { throw new NotImplementedException("Methode differenting with params not implemented"); } var tmpNewMethode = new MethodeContainer(); tmpNewMethode.Name = tmpMethodeName; tmpNewMethode.ModifierList = new List <string> { "public" }; tmpClass.MethodeList.Add(tmpNewMethode); } } } IResolveMethodeContentToIL tmpCodeHandler = new JavaMethodeCodeResolver(); foreach (var tmpClass in tmpClassList) { foreach (var tmpMethode in tmpClass.MethodeList) { tmpCodeHandler.Resolve(tmpMethode); } } foreach (var tmpClassouter in tmpClassList) { foreach (var tmpClass in tmpClassouter.InnerClasses) { foreach (var tmpMethode in tmpClass.MethodeList) { tmpCodeHandler.Resolve(tmpMethode); } } } //Fill them into the object Information tmpObjectInformation.FillClasses(tmpAdditionalClasses); return(tmpObjectInformation); }
private NewObjectDeclaration HandleCreatorContext(CreatorContext inContext, VariableDeclaration inVariableDeclaration) { var tmpEntry = new NewObjectDeclaration(); ConstantValue tmpValue = null; if (inContext.createdName() != null) { tmpValue = new ConstantValue(); tmpValue.Type = new TypeContainer() { Name = inContext.createdName().GetText() }; tmpEntry.InnerCode = tmpValue; } if (inContext.nonWildcardTypeArguments() != null) { throw new NotImplementedException("Not done yet"); } if (inContext.classCreatorRest() != null) { var tmpClass = inContext.classCreatorRest(); if (tmpClass.arguments()?.expressionList() != null) { tmpEntry.ArgumentList = new List <CodeBlock>(); foreach (var tmpExpression in tmpClass.arguments().expressionList().expression()) { var tmpBlock = new CodeBlock(); HandleExpressionContext(tmpBlock, tmpExpression); tmpEntry.ArgumentList.Add(tmpBlock); } } if (tmpClass.classBody() != null) { if (inVariableDeclaration == null) { throw new NotImplementedException("Not done yet"); } var tmpClassContainer = new ClassContainer() { Namespace = "", ModifierList = ParentClass.ModifierList.Where(inItem => inItem != "abstract").ToList(), }; JavaAntlrClassLoader.ManageClassBodyContext(tmpClassContainer, "", tmpClass.classBody()); tmpClassContainer.Type = new TypeContainer(ParentClass.Name + "_" + ParentClass.InnerClasses.Count); tmpClassContainer.InterfaceList.Add(inVariableDeclaration.Type); ParentClass.InnerClasses.Add(tmpClassContainer); tmpValue = new ConstantValue(); tmpValue.Type = new TypeContainer() { Name = tmpClassContainer.Name }; tmpEntry.InnerCode = tmpValue; } } if (inContext.arrayCreatorRest() != null) { tmpValue.Type.IsArray = true; var tmpBlock = new CodeBlock(); HandleExpressionContext(tmpBlock, inContext.arrayCreatorRest().expression()[0]); var tmpArrayInizialiser = tmpBlock.CodeEntries[0]; tmpValue.Type.ArrayInizialiser = tmpArrayInizialiser; } return(tmpEntry); }
/// <summary> /// Handling of an Expression Block /// </summary> /// <param name="inCodeBlock"></param> /// <param name="inBlockStatement"></param> public void HandleExpressionContext(CodeBlock inCodeBlock, ExpressionContext inBlockStatement, VariableDeclaration inVariable = null) { if (inBlockStatement == null) { return; } //if (inBlockStatement.IDENTIFIER() != null) //{ // inCodeBlock.CodeEntries.Add(new ConstantValue { Value = inBlockStatement.IDENTIFIER().GetText() }); //} //else if (inBlockStatement.THIS() != null) //{ // throw new NotImplementedException("Not done yet"); //} //else if (inBlockStatement.NEW() != null) //{ // throw new NotImplementedException("Not done yet"); //} //else if (inBlockStatement.SUPER() != null) //{ // throw new NotImplementedException("Not done yet"); //} //else if (inBlockStatement.INSTANCEOF() != null) //{ // throw new NotImplementedException("Not done yet"); //} //else { if (inBlockStatement.primary() != null) { //Primary Value analyse type var tmpPrimary = inBlockStatement.primary(); var tmpPrimaryAsText = tmpPrimary.GetText(); if (tmpPrimary.expression() != null) { var tmpCodeBlock = new CodeBlockContainer(); HandleExpressionContext(tmpCodeBlock.InnerBlock, tmpPrimary.expression(), inVariable); inCodeBlock.CodeEntries.Add(tmpCodeBlock); } else if (tmpPrimary.literal() != null) { inCodeBlock.CodeEntries.Add(new ConstantValue { Value = tmpPrimaryAsText }); } else if (tmpPrimary.typeTypeOrVoid() != null) { var tmpType = JavaAntlrClassLoader.CreateTypeContainerFromType(tmpPrimary.typeTypeOrVoid()); var tmpConst = new ConstantValue { Type = tmpType, Value = tmpPrimary.typeTypeOrVoid().typeType().GetText() }; if (tmpPrimary.CLASS() != null) { var tmpVariableAccess = new VariableAccess(); tmpVariableAccess.Access = tmpConst; tmpVariableAccess.Child = new ConstantValue { Value = "class" }; inCodeBlock.CodeEntries.Add(tmpConst); } else { inCodeBlock.CodeEntries.Add(tmpConst); } } else if (tmpPrimary.nonWildcardTypeArguments() != null) { throw new NotImplementedException("Not done yet"); } else if (tmpPrimary.explicitGenericInvocationSuffix() != null) { throw new NotImplementedException("Not done yet"); } else if (tmpPrimary.arguments() != null) { throw new NotImplementedException("Not done yet"); } else { inCodeBlock.CodeEntries.Add(new ConstantValue { Value = tmpPrimaryAsText }); } } else if (inBlockStatement.expression().Length == 1 && inBlockStatement.typeType() != null) { //Type Conversion var tmpInfo = inBlockStatement.expression(); var tmpConverter = new TypeConversion(); tmpConverter.PreconversionValue = new CodeBlock(); HandleExpressionContext(tmpConverter.PreconversionValue, tmpInfo[0]); var tmpType = inBlockStatement.typeType(); tmpConverter.Type = JavaAntlrClassLoader.GetTypeContainer(tmpType); inCodeBlock.CodeEntries.Add(tmpConverter); } else if (inBlockStatement.expression().Length == 2 && inBlockStatement.children[1].GetText() == "[") { var tmpAccess = new VariableAccess { }; var tmpCodeBlock = new CodeBlock(); HandleExpressionContext(tmpCodeBlock, inBlockStatement.expression()[0], null); tmpAccess.Access = tmpCodeBlock.CodeEntries[0]; tmpCodeBlock = new CodeBlock(); HandleExpressionContext(tmpCodeBlock, inBlockStatement.expression()[1], null); tmpAccess.Child = new CodeBlockContainer { InnerBlock = tmpCodeBlock }; tmpAccess.IsArrayAccess = true; inCodeBlock.CodeEntries.Add(tmpAccess); } else if (inBlockStatement.expression().Length == 2 && inBlockStatement.children[1].GetText() != "=") { var tmpCodeExpression = new CodeExpression { Manipulator = JavaStaticInfo.GetManipulator(string.Join("", inBlockStatement.children .Where(inItem => inItem is ITerminalNode) .Select(inItem => inItem.GetText()))) }; var tmpCodeBlock = new CodeBlock(); HandleExpressionContext(tmpCodeBlock, inBlockStatement.expression()[0], inVariable); tmpCodeExpression.SubClauseEntries.Add(tmpCodeBlock); tmpCodeBlock = new CodeBlock();//Second Code Block HandleExpressionContext(tmpCodeBlock, inBlockStatement.expression()[1], inVariable); tmpCodeExpression.SubClauseEntries.Add(tmpCodeBlock); inCodeBlock.CodeEntries.Add(tmpCodeExpression); } else { var tmpChildList = inBlockStatement.children; if (tmpChildList.Count > 2) { var tmpSecondChildText = tmpChildList[1].GetText(); if (tmpSecondChildText == "=") { //SetVariable with Value var tmpVarSetter = new SetFieldWithValue(); HandleExpressionContext(tmpVarSetter.VariableToAccess, tmpChildList[0] as ExpressionContext, inVariable); HandleExpressionContext(tmpVarSetter.ValueToSet, tmpChildList[2] as ExpressionContext, inVariable); inCodeBlock.CodeEntries.Add(tmpVarSetter); } else if (JavaStaticInfo.VariableOperators.ContainsKey(tmpSecondChildText)) { var tmpCodeExpression = new CodeExpression { Manipulator = JavaStaticInfo.GetManipulator(tmpSecondChildText) }; var tmpCodeBlock = new CodeBlock(); HandleExpressionContext(tmpCodeBlock, tmpChildList[0] as ExpressionContext, inVariable); tmpCodeExpression.SubClauseEntries.Add(tmpCodeBlock); tmpCodeBlock = new CodeBlock();//Second Code Block HandleExpressionContext(tmpCodeBlock, tmpChildList[2] as ExpressionContext, inVariable); tmpCodeExpression.SubClauseEntries.Add(tmpCodeBlock); inCodeBlock.CodeEntries.Add(tmpCodeExpression); } //Multi Part Property Access else if (tmpSecondChildText == ".") { VariableAccess tmpParent = null; for (var tmpI = 0; tmpI < tmpChildList.Count; tmpI += 2) { var tmpChild = tmpChildList[tmpI]; var tmpAccess = new VariableAccess(); if (tmpChild is ExpressionContext) { var tmpCodeBlock = new CodeBlock(); HandleExpressionContext(tmpCodeBlock, tmpChild as ExpressionContext, null); tmpAccess.Access = tmpCodeBlock.CodeEntries[0]; } else if (tmpChild is MethodCallContext) { var tmpResult = HandleMethodeCall(tmpChild as MethodCallContext); tmpAccess.Access = tmpResult; } else if (tmpChild is TerminalNodeImpl) { var tmpChildText = tmpChild.GetText(); if (tmpChildText == ".") { } else if (RegexHelper.WordCheck.IsMatch(tmpChildText)) { tmpAccess.Access = new ConstantValue(tmpChildText); } else { throw new NotImplementedException("Not done yet"); } } else { throw new NotImplementedException("Not done yet"); } if (tmpParent != null) { tmpParent.Child = tmpAccess; } else { inCodeBlock.CodeEntries.Add(tmpAccess); } tmpParent = tmpAccess; } } else if (tmpSecondChildText == "?") { //Implement Elvis var tmpStatement = new StatementCode { StatementType = StatementTypeEnum.Elvis, StatementCodeBlocks = new List <CodeBlock>() }; //Boolean query var tmpCodeBlock = new CodeBlock(); HandleExpressionContext(tmpCodeBlock, tmpChildList[0] as ExpressionContext, inVariable); tmpStatement.StatementCodeBlocks.Add(tmpCodeBlock); //First Result tmpCodeBlock = new CodeBlock(); HandleExpressionContext(tmpCodeBlock, tmpChildList[2] as ExpressionContext, inVariable); tmpStatement.StatementCodeBlocks.Add(tmpCodeBlock); //Second Result tmpCodeBlock = new CodeBlock(); HandleExpressionContext(tmpCodeBlock, tmpChildList[4] as ExpressionContext, inVariable); tmpStatement.StatementCodeBlocks.Add(tmpCodeBlock); inCodeBlock.CodeEntries.Add(tmpStatement); } else { throw new NotImplementedException("Not done yet"); } } else if (tmpChildList.Count == 1) { var tmpValue = tmpChildList[0] as MethodCallContext; MethodeCall tmpMethodeCall = HandleMethodeCall(tmpValue); inCodeBlock.CodeEntries.Add(tmpMethodeCall); } else if (tmpChildList.Count == 2 && tmpChildList[1] is ExpressionContext) { if (tmpChildList[0].GetText() == "!") { var tmpCodeExpression = new CodeExpression { Manipulator = JavaStaticInfo.GetManipulator(tmpChildList[0].GetText()) }; tmpCodeExpression.SubClauseEntries = new List <CodeBlock> { new CodeBlock() }; HandleExpressionContext(tmpCodeExpression.SubClauseEntries[0], tmpChildList[1] as ExpressionContext, inVariable); inCodeBlock.CodeEntries.Add(tmpCodeExpression); } else if (tmpChildList[0].GetText() != "-") { throw new NotImplementedException("Not done yet"); } else { HandleExpressionContext(inCodeBlock, tmpChildList[1] as ExpressionContext, inVariable); (inCodeBlock.CodeEntries.Last() as ConstantValue).Value = "-" + (inCodeBlock.CodeEntries.Last() as ConstantValue).Value; } } else if (tmpChildList.Count == 2 && tmpChildList[0] is ExpressionContext) { if (tmpChildList[1].GetText() != "--" && tmpChildList[1].GetText() != "++") { throw new NotImplementedException("Not done yet"); } var tmpCodeExpression = new CodeExpression { Manipulator = JavaStaticInfo.GetManipulator(tmpChildList[1].GetText()) }; tmpCodeExpression.SubClauseEntries = new List <CodeBlock> { new CodeBlock() }; HandleExpressionContext(tmpCodeExpression.SubClauseEntries[0], tmpChildList[0] as ExpressionContext, inVariable); inCodeBlock.CodeEntries.Add(tmpCodeExpression); } else if (tmpChildList.Count == 2) { if (tmpChildList[0].GetText() != "new") { throw new NotImplementedException("Not done yet"); } inCodeBlock.CodeEntries.Add(HandleCreatorContext(tmpChildList[1] as CreatorContext, inVariable)); } else { throw new NotImplementedException("Not done yet"); } } } }