You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by GitBox <gi...@apache.org> on 2020/05/29 16:12:52 UTC

[GitHub] [incubator-daffodil] mbeckerle commented on a change in pull request #274: WIP: Daffodil 2202 initial codegen

mbeckerle commented on a change in pull request #274:
URL: https://github.com/apache/incubator-daffodil/pull/274#discussion_r432590663



##########
File path: daffodil-core/src/main/scala/org/apache/daffodil/runtime2/generators/ElementParserGenerator.scala
##########
@@ -0,0 +1,176 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.daffodil.runtime2.generators
+
+import scala.collection.JavaConverters._
+
+import org.apache.daffodil.codegen.ast._
+import org.apache.daffodil.dpath.NodeInfo
+import org.apache.daffodil.exceptions.Assert
+import org.apache.daffodil.dsom.ElementBase
+
+class ElementParserGenerator(context: ElementBase, contentParserGenerator: ParserGenerator)
+  extends ParserGenerator {
+
+  def toPrimitive(primType: NodeInfo.PrimType): TypeDefinition = {
+    import NodeInfo.PrimType
+    primType match {
+      case PrimType.Long => Primitive.LONG
+      case PrimType.Int => Primitive.INTEGER
+      case _ => context.SDE("Unsupported primitive type: " + primType)
+    }
+  }
+
+  def toComplexType(e: ElementBase): TypeDefinition = {
+    // Stubbed code
+    Expressions.typeOf("e2")
+  }
+
+  def toParseMethod(e: ElementBase): Method = {
+    Expressions.method(Expressions.typeOf("E2_Type"), "parseSelf", Primitive.VOID,
+      Nil.asJava, Nil.asJava)
+  }
+
+  override def generateCode(cgState: CodeGeneratorState): CodeGeneratorState = {
+
+    val childDecls =
+      context.elementChildren.map { child =>
+        if (child.optPrimType.isDefined)
+          new FieldDeclaration(toPrimitive(child.optPrimType.get), child.name)
+        else
+          new FieldDeclaration(toComplexType(child), child.name)
+      }
+

Review comment:
       Below is where we get in trouble.
   Line 61 specifically has no "target" because the target is 'this' class object's e1 field. 
   But later when generating code we get a null pointer exception when it tries to access the target of this FieldReference object.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org