Wiki

Ticket #275: java-fix.patch

File java-fix.patch, 4.1 KB (added by hopscc, 11 years ago)
  • Source/BackEndJvm/JavaGenerator.cobra

     
    3838        _fullJarFileName = outName 
    3939        return outName 
    4040         
     41    def createJavaFile(fileName as String, contents as String) 
     42        #print 'output: ', contents 
     43        File.writeAllText(fileName, contents) 
     44        .addIntermediateFile(fileName) 
     45 
    4146    def writeJava 
    4247        Node.setCompiler(this) 
    4348        try 
     
    5661             
    5762    def writeJavaTestInvocation 
    5863        # TODO 
     64        #fileName = 'test-[dt.year][dt.month][dt.day][dt.hour][dt.minute].java'   # to-do: format the numbers to have leading zeros 
     65        #w = CodeCommentLineWriter() 
     66        # ... 
     67        #.createJavaFile(fileName, w.output) 
    5968        print 'TODO: writeJavaTestInvocation' 
    6069 
    6170    def compileJava 
     
    276285    def newJavaFile( cobraModuleName as String, javaFileName as String) as CurlyWriter 
    277286        #print 'newJavaFile [javaFileName]' 
    278287        sw = CodeCommentLineWriter() 
    279         .addIntermediateFile(javaFileName) 
    280288        sw.start(cobraModuleName) 
    281289        sw.write('// [javaFileName] from [cobraModuleName]\n') 
    282290        sw.write('// Generated by Cobra-[CommandLine.versionString]\n') 
    283291        sw.write('// on [DateTime.now]\n') 
    284292        # TODO: list op sys 
    285293        sw.write('\n') 
    286         File.writeAllText(javaFileName, sw.output) 
    287294        return sw 
    288295     
    289296         
     
    417424            else 
    418425                .topNameSpace.writeJavaDef(sw) 
    419426            d = sw.curlyToCobraLineNum 
     427            (.compiler to Compiler).createJavaFile(.javaFileName, sw.output) 
    420428        return d 
    421429         
    422430    def writeJavaTestInvocation(sw as CurlyWriter) is override 
     
    627635                    decl.writeJavaDef(sw) 
    628636                    javaToCobraLineNum = sw.curlyToCobraLineNum 
    629637                    compiler.storeJavaFileInfo(cobraModName, javaToCobraLineNum) 
     638                    (.compiler to Compiler).createJavaFile(javaFileName, sw.output) 
    630639             
    631640            if decl inherits Box, .compiler.boxStack.pop 
    632641 
     
    13091318        base.writeJavaDef(sw) 
    13101319        # TODO 
    13111320        #if .type.isReference and not .type inherits NilableType 
    1312         #   sw.write(r'[Cobra.Core.NotNull] ')  
     1321        #   sw.write(r'[Cobra.Core.NotNull] ') # TODO: annotations on params avail in Java8 
    13131322        branch .direction 
    13141323            on Direction.In, pass 
    13151324            on Direction.InOut, sw.write('/*inOut*/')   # default 
    13161325            on Direction.Out, sw.write('/*out*/')       # TODO 
    13171326        sw.write('[.type.javaParamRef] [.javaName]') 
     1327#       if .optValue    # Net4 optional param 
     1328#           detail='For java at the moment you will need to recode the optional parameter method as a set of overloaded (possibly cascaded) methods with the desired number of parameters.' 
     1329#           .compiler.warning(this, 'Java does not support optional parameters. Default parameter value setting is ignored. [detail]') 
     1330#           #sw.write('=') 
     1331#           #_optValue.writeSharpDef(sw) 
    13181332 
    13191333    def writeJavaDefSansReferenceLabels(sw as CurlyWriter) 
    13201334        """ 
    13211335        Writes the parameter declaration but without Java "out" or "ref"--these are not available for 
    13221336        contract methods (require_foo and ensure_foo) because contracts cannot modify arguments. 
    13231337        """ 
    1324         # skip the [NotNull] as well since it's not really needed 
    13251338        sw.write('[.type.javaRef] [.javaName]')      
    13261339 
    13271340 
     
    35233539                on + 8, s = 'short'  # unsigned Byte uint8 
    35243540                on -16, s = 'short'  #'Int16' 
    35253541                on +16, s = 'int'    # unsigned short UInt16' 
    3526                 on -32, s = 'int'    # int32 
     3542                on -32, s = ''       # int32 
    35273543                on +32, s = 'long'   # unsigned int32 
    3528                 on -64, s = 'long' 
     3544                on -64, s = 'L'      #'long' 
    35293545                on +64, s = 'long'   # unsigned int64 
    35303546                else, throw FallThroughException(info) 
    35313547        if s.length <= 2 
  • Source/BackEndCommon/CurlyWriter.cobra

     
    55 
    66 
    77 
    8 class CurlyWriter is abstract 
     8class CurlyWriter is abstract implements IDisposable 
    99 
    1010    var _sb as StringBuilder 
    1111 
     
    140140     
    141141    def output as String 
    142142        return _sb.toString 
     143     
     144    def dispose is new 
     145        pass 
     146         
    143147 
    144148 
    145149class CodePoundLineWriter inherits CurlyWriter